|
71 | 71 | # if there's no checkout folder - checkout one.
|
72 | 72 | if ! [[ -d $CHECKOUT_PATH ]]; then
|
73 | 73 | echo "-- $FRIENDLY_CHECKOUT_PATH is missing - checking out.."
|
74 |
| - git clone --single-branch --branch $BASE_BRANCH $REMOTE_URL $CHECKOUT_PATH |
| 74 | + git clone --single-branch --depth 1 --branch $BASE_BRANCH $REMOTE_URL $CHECKOUT_PATH |
75 | 75 | else
|
76 | 76 | echo "-- checking $FRIENDLY_CHECKOUT_PATH folder - OK"
|
77 | 77 | fi
|
@@ -102,11 +102,30 @@ else
|
102 | 102 | git remote add $REMOTE_BROWSER_UPSTREAM $REMOTE_URL
|
103 | 103 | fi
|
104 | 104 |
|
105 |
| -# If not, fetch from REMOTE_BROWSER_UPSTREAM and check one more time. |
106 |
| -git fetch $REMOTE_BROWSER_UPSTREAM $BASE_BRANCH |
107 |
| -if ! git cat-file -e $BASE_REVISION^{commit}; then |
108 |
| - echo "ERROR: $FRIENDLY_CHECKOUT_PATH/ does not include the BASE_REVISION (@$BASE_REVISION). Wrong revision number?" |
109 |
| - exit 1 |
| 105 | +# Check if our checkout contains BASE_REVISION. |
| 106 | +# If not, fetch from REMOTE_BROWSER_UPSTREAM and slowly fetch more and more commits |
| 107 | +# until we find $BASE_REVISION. |
| 108 | +# This technique allows us start with a shallow clone. |
| 109 | +if ! git cat-file -e $BASE_REVISION^{commit} 2>/dev/null; then |
| 110 | + # Detach git head so that we can fetch into branch. |
| 111 | + git checkout --detach >/dev/null 2>/dev/null |
| 112 | + |
| 113 | + # Fetch 128 commits first, and then double the amount every iteration. |
| 114 | + FETCH_DEPTH=128 |
| 115 | + SUCCESS="no" |
| 116 | + while (( FETCH_DEPTH <= 8192 )); do |
| 117 | + echo "Fetching ${FETCH_DEPTH} commits to find base revision..." |
| 118 | + git fetch --depth "${FETCH_DEPTH}" $REMOTE_BROWSER_UPSTREAM $BASE_BRANCH |
| 119 | + FETCH_DEPTH=$(( FETCH_DEPTH * 2 )); |
| 120 | + if git cat-file -e $BASE_REVISION^{commit} >/dev/null; then |
| 121 | + SUCCESS="yes" |
| 122 | + break; |
| 123 | + fi |
| 124 | + done |
| 125 | + if [[ "${SUCCESS}" == "no" ]]; then |
| 126 | + echo "ERROR: $FRIENDLY_CHECKOUT_PATH/ does not include the BASE_REVISION (@$BASE_REVISION). Wrong revision number?" |
| 127 | + exit 1 |
| 128 | + fi |
110 | 129 | fi
|
111 | 130 |
|
112 | 131 | echo "-- checking $FRIENDLY_CHECKOUT_PATH repo has BASE_REVISION (@$BASE_REVISION) commit - OK"
|
|
0 commit comments