From c4c4aed9b794b4c98d013d60634209237dc5718a Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 29 Jun 2020 16:10:42 -0700 Subject: [PATCH] jobd/gc.sh: alter is_dirty semantics In preparation for checking the "repack" "signature" hash, change the is_dirty function to allow up to two "normally named" packs to exist (provided there is at least one ref) before declaring the repository to be dirty. Except for the change to allow two "normally named" packs instead of one, the semantics otherwise remain the same. Signed-off-by: Kyle J. McKay --- jobd/gc.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/jobd/gc.sh b/jobd/gc.sh index 877f43e..25345f5 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -114,24 +114,24 @@ compact_reflogs() { done } -# return true if there's more than one objects/pack-.pack file or +# return true if there's more than two objects/pack-.pack files or # ANY sha-1 files in objects or -# there's one pack and it's not a normal pack name or -# there's one pack but not any refs +# there's one or two packs but at least one does not have a normal pack name or +# there's at least one pack but not any refs is_dirty() { - _packs="$(find -L objects/pack -name "pre-auto-gc-[12].pack" -prune -o -name "*.pack" -type f -print 2>/dev/null | head -n 2)" + _packs="$(find -L objects/pack -name "pre-auto-gc-[12].pack" -prune -o -name "*.pack" -type f -print 2>/dev/null | head -n 3)" v_cnt _packscnt $_packs - if [ $_packscnt -gt 1 ]; then + if [ $_packscnt -gt 2 ]; then return 0 fi - if [ $_packscnt -eq 1 ]; then - # the single pack name is in $_packs - _packs="${_packs%.pack}" - _packs="${_packs#objects/pack/}" - case "$_packs" in + if [ $_packscnt -gt 0 ]; then + for _pack in $_packs; do + _pack="${_pack%.pack}" + _pack="${_pack#objects/pack/}" + case "$_pack" in pack-*) - _packs="${_packs#pack-}" - if [ "${#_packs}" -lt 40 ] || [ "${_packs#*[!0-9a-fA-F]}" != "$_packs" ]; then + _pack="${_pack#pack-}" + if [ "${#_pack}" -lt 40 ] || [ "${_pack#*[!0-9a-fA-F]}" != "$_pack" ]; then # name not exclusively 40 or more hexadecimal digits makes it dirty return 0 fi @@ -140,14 +140,15 @@ is_dirty() { # abnormal name makes it dirty return 0 ;; - esac + esac + done fi _objs=$(find -L objects/$octet -name "$octet19*" -type f -print 2>/dev/null | head -n 1 | LC_ALL=C wc -l) [ $_objs -eq 0 ] || return 0 - [ $_packscnt -eq 1 ] || return 1 + [ $_packscnt -gt 0 ] || return 1 # we do this check last because it's potentially the most expensive; # at this point we know we do not have any loose objects, but we do - # have one pack that's named "normally"; empty refs => dirty + # have one or two packs that are named "normally"; empty refs => dirty is_empty_refs_dir } -- 2.11.4.GIT