]> git.ozlabs.org Git - next-scripts/commitdiff
fetch_trees: use ls-remote to check the ref SHA
authorStephen Rothwell <sfr@canb.auug.org.au>
Mon, 28 Apr 2025 08:41:39 +0000 (18:41 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Mon, 28 Apr 2025 08:41:39 +0000 (18:41 +1000)
before fetching = - in the hope that that is a much lower
overhead operation on the remote

fetch_trees

index a6276b3a90910287e938412e88c3878d0b2788fc..92accdd2e0f2ccd08a354fb92a77f776554070a2 100755 (executable)
@@ -22,9 +22,27 @@ if [ "$1" = '-s' ]; then
        shift
 fi
 
+# shellcheck disable=SC2317
 fetch_git()
 {
-       git fetch "$1"
+       local name="$1" branch="$2" old_sha="$3" new_sha
+
+       if ! new_sha=$(git ls-remote "$name" "refs/heads/$branch") ||
+          [ -z "$new_sha" ]; then
+               printf '%s: Could not fetch %s branch %s\n' 'fetch_git' "$name" "$branch" >&2
+               printf '%s\n' "$old_sha"
+               return
+       fi
+       new_sha="${new_sha%%"${_TAB}"*}"
+       if [ "$new_sha" = "$old_sha" ]; then
+               printf '%s\n' "$old_sha"
+               return
+       fi
+       if git fetch "$name"; then
+               git rev-parse --verify "$name/$branch"
+       else
+               printf '%s\n' "$old_sha"
+       fi
 }
 
 trees="$*"
@@ -57,8 +75,7 @@ for name in $trees; do
        if [ "$tfun" = 'function' ]; then
                branch=$(get_remote_branch "$name")
                old_sha=$(git rev-parse --quiet --verify "$name/$branch")
-               "$fun" "$name"
-               new_sha=$(git rev-parse --verify "$name/$branch")
+               new_sha=$("$fun" "$name" "$branch" "$old_sha")
                check_dups "$name" origin/master "$new_sha"
                if ! [ "$new_sha" = "$old_sha" ]; then
                        "$tools_dir"/check_commits ^origin/master "$old_sha..$new_sha"