Skip to content

Commit fca8316

Browse files
authored
Implement switching to another expected commit (#10)
Do not require manual removal of the repository under src/{musl,llvm} before checking out another expected commit.
1 parent e0f181f commit fca8316

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

build.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ check_repo_sha() {
2020
fi
2121
}
2222

23+
# NOTE: Non-clean status of the working directory is currently ignored.
24+
# This makes it possible to checkout the expected commit first
25+
# and perform quick local experiments later (until switching to another
26+
# expected commit).
27+
fetch_git_commit() {
28+
local repo_path="$1"
29+
local repo_url="$2"
30+
local branch="$3"
31+
local expected_sha="$4"
32+
33+
if [ ! -d "$repo_path" ]; then
34+
# No repository found - initialize one and create a dummy commit,
35+
# for rev-parse to return *something*.
36+
echo "Initializing git repository at $repo_path..."
37+
git init --initial-branch=temp "$repo_path"
38+
git -C "$repo_path" commit --allow-empty -m "Dummy commit on a dummy branch"
39+
fi
40+
41+
local current_sha="$(git -C "$repo_path" rev-parse HEAD)"
42+
if [ "$current_sha" != "$expected_sha" ]; then
43+
local timestamp="$(date '+%Y%m%d_%H_%M_%S')"
44+
echo "$repo_path: switching from $current_sha to $expected_sha ($branch)..."
45+
git -C "$repo_path" fetch --depth 1 "$repo_url" "$branch"
46+
# Create a branch, so that subsequent fetch operations can ask the remote
47+
# git not to re-pack the existing objects.
48+
git -C "$repo_path" checkout -b "fetch-$timestamp" FETCH_HEAD
49+
fi
50+
}
51+
2352
fetch_sources() {
2453
. ./config
2554
. ./scripts/global-vars
@@ -34,8 +63,8 @@ fetch_sources() {
3463
local musl_repo="$2"
3564

3665
mkdir -p "$ROOT/src"
37-
test -d "$ROOT/src/llvm" || git clone --depth 1 -b "$LLVM_BRANCH" "$llvm_repo" "$ROOT/src/llvm"
38-
test -d "$ROOT/src/musl" || git clone --depth 1 -b "$MUSL_BRANCH" "$musl_repo" "$ROOT/src/musl"
66+
fetch_git_commit "$ROOT/src/llvm" "$llvm_repo" "$LLVM_BRANCH" "$LLVM_SHA"
67+
fetch_git_commit "$ROOT/src/musl" "$musl_repo" "$MUSL_BRANCH" "$MUSL_SHA"
3968

4069
local SOURCE_TARBALL=linux-$LINUX_KERNEL_VERSION.tar.xz
4170
curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${LINUX_KERNEL_VERSION%%.*}.x/$SOURCE_TARBALL" \

0 commit comments

Comments
 (0)