From 680157999e2c925e4687d08e1072554bcd2cc609 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 10 Jun 2020 20:04:41 -0700 Subject: [PATCH] jobd/gc-util-functions.sh: add lotsa_single_object_packs function If there are "lotsa" single object (or zero object) packs, return true, otherwise false. Signed-off-by: Kyle J. McKay --- jobd/gc-util-functions.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/jobd/gc-util-functions.sh b/jobd/gc-util-functions.sh index c934244..5c9b8d5 100755 --- a/jobd/gc-util-functions.sh +++ b/jobd/gc-util-functions.sh @@ -172,6 +172,25 @@ lotsa_loose_pruned_objects() { lotsa_loose_objects } +# a "single object" pack is either a pack containing just one object +# or a pack containing zero objects (which is a degenerate case that +# normally can never happen). And it must have a name matching +# the pack-*.pack pattern where either the "infix" suffix is "_l" +# or the name does not contain any "_" characters at all (and, obviously, +# must have a matching .idx file). Any .keep, .bundle, or .bitmap +# associated packs are automatically excluded from the count. +# "lotsa" here is defined as 20 or more. +lotsa_single_object_packs() { + __lpo="--exclude-no-idx --exclude-keep --exclude-bitmap --exclude-bndl" + _lpo01="$__lpo --exclude-limit 2" + # "$0=substr($0,19,length-23)" strips the leading "objects/pack/pack-" and trailing ".pack" + _sopacks="$( + list_packs --quiet $_lpo01 objects/pack 2>/dev/null | + LC_ALL=C awk 'BEGIN {c=0} {$0=substr($0,19,length-23)} !/_/ || /^[0-9a-f]*_l$/ {c+=1} END {print c}' + )" || : + [ ${_sopacks:-0} -ge 20 ] +} + # pack any existing, non-packed loose objects into a new _l.pack file then run prune-packed # note that prune-packed is NOT run beforehand -- the caller must do that if needed # loose objects need not be part of complete commits/trees as --weak-naming is used -- 2.11.4.GIT