Skip to content

Commit b94a7c0

Browse files
authored
devops: speedup initial browser checkout (#4352)
Instead of checking out the whole repository, we now do a shallow clone. We then gradually "unshallow" the clone, looking for the `BASE_REVISION`. This should fix experimental mac-11 builder.
1 parent bba8c98 commit b94a7c0

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

browser_patches/prepare_checkout.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fi
7171
# if there's no checkout folder - checkout one.
7272
if ! [[ -d $CHECKOUT_PATH ]]; then
7373
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
7575
else
7676
echo "-- checking $FRIENDLY_CHECKOUT_PATH folder - OK"
7777
fi
@@ -102,11 +102,30 @@ else
102102
git remote add $REMOTE_BROWSER_UPSTREAM $REMOTE_URL
103103
fi
104104

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
110129
fi
111130

112131
echo "-- checking $FRIENDLY_CHECKOUT_PATH repo has BASE_REVISION (@$BASE_REVISION) commit - OK"

0 commit comments

Comments
 (0)