From 8f169d233a9b83cc147803588bbe053e48f18c3c Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 29 Jun 2020 15:31:10 -0700 Subject: [PATCH] jobd/gc.sh: switch the gc "signature" hash to use ltsha256 When generating the final "repack" "signature" hash, ALL of the existing ref logs are fed into the hash function. Normally there aren't any ref logs. However, if any worktrees exist or the repository has been made not-bare, there very well could be. A repository with a lot of ongoing development activity could potentially have a lot of very long files in the "logs" subdirectory. Sucking all of them plus the full packed-refs file into memory at once shouldn't be a problem... There really should always be enough memory to do this... But, just in case... Avoid any unnecessary memory bloat (as well as an outdated SHA-1 algorithm) and switch all of the gc "signature" hashes from using `git hash-object -t blob --stdin` to `ltsha256`. Signed-off-by: Kyle J. McKay --- jobd/gc.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/jobd/gc.sh b/jobd/gc.sh index 6357970..877f43e 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -330,6 +330,11 @@ pack_is_complete() { echo "$_headsha" } +# write the hexadecimal sha256 hash of stdin plus a trailing newline to stdout +sig_hash_stdin() { + "$cfg_basedir/bin/ltsha256" +} + # Compute a "signature" for the refs in the specified (default .) repository. # Instead of passing --head to show-ref, the actual contents of HEAD are used # to capture changes in HEAD's symbolic-ref value that would otherwise be missed. @@ -337,7 +342,7 @@ pack_is_complete() { # $2 => --git-dir to use, defaults to "." v_compute_refs_sighash() { eval "$1="'"$({ cat "${2:-.}/HEAD"; git --git-dir="${2:-.}" show-ref; } | - git hash-object -t blob --stdin)"' + sig_hash_stdin)"' } # On return a "$lockf" will have been created that must be removed when gc is done @@ -830,7 +835,7 @@ if [ -n "$skipgc" ]; then if [ -n "$skipgc" ]; then # a previous packs sig is available, check for a match _chksig="$(list_packs -C objects/pack --exclude-no-idx --quiet . | - LC_ALL=C sort | git hash-object -t blob --stdin)" || : + LC_ALL=C sort | sig_hash_stdin)" || : [ "$phash" = "$_chksig" ] || skipgc= fi fi @@ -1443,7 +1448,7 @@ compute_extra_reachables >>repack/packed-refs # Now calculate the final repack signature hash # Since we do _allow_ worktrees and we do _allow_ ref logs, # the ref logs of such must be accounted for here as well -_rpksig="$(cat_all_ref_logs repack/packed-refs | git hash-object -t blob --stdin)" +_rpksig="$(cat_all_ref_logs repack/packed-refs | sig_hash_stdin)" echo "$_rpksig" >repack/repack.sighash # Subtract the primary refs @@ -1776,7 +1781,7 @@ rm -rf repack psighash="$(if [ -n "$packs" ] || [ -n "$spacks" ]; then printf 'pack-%s.pack\n' $packs $spacks - fi | LC_ALL=C sort | git hash-object -t blob --stdin)" + fi | LC_ALL=C sort | sig_hash_stdin)" config_set_raw girocco.gcsig.packs "$psighash" config_set_raw girocco.gcsig.refs "$rsighash" config_set_raw girocco.gcsig.repack "$repacksig" -- 2.11.4.GIT