From: Stephen Rothwell Date: Mon, 28 Apr 2025 08:41:39 +0000 (+1000) Subject: fetch_trees: use ls-remote to check the ref SHA X-Git-Url: https://git.ozlabs.org/?a=commitdiff_plain;h=9c0f58ab626fbb1d0eebc6c5da8d877ca67defce;p=next-scripts fetch_trees: use ls-remote to check the ref SHA before fetching = - in the hope that that is a much lower overhead operation on the remote --- diff --git a/fetch_trees b/fetch_trees index a6276b3..92accdd 100755 --- a/fetch_trees +++ b/fetch_trees @@ -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"