From 061d2d0ceb46f4418c0435b3742a7242a7022525 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 30 Dec 2017 16:22:46 -0800 Subject: [PATCH] shlib.sh: add check_and_set_needsgc function The check_and_set_needsgc function inspects the current directory repository and sets .needsgc if it's not already set and the repository could benefit from at least a "mini" garbage collection. Signed-off-by: Kyle J. McKay --- shlib.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/shlib.sh b/shlib.sh index 2ce476d..f68655f 100644 --- a/shlib.sh +++ b/shlib.sh @@ -754,6 +754,37 @@ _update_head_symref() { ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || : } +# current directory must already be set to Git repository +# if the directory needs to have gc run and .needsgc is not already set +# then .needsgc will be set triggering a "mini" gc at the next opportunity +# Girocco shouldn't generate any loose objects but we check for that anyway +check_and_set_needsgc() { + ! [ -e .needsgc ] || return 0 + _packs= + { _packs="$(list_packs --quiet --count --exclude-no-idx --exclude-keep objects/pack || :)" || :; } 2>/dev/null + if [ "${_packs:-0}" -ge 20 ]; then + >.needsgc + return 0 + fi + _logfiles= + { _logfiles="$(($(find -L reflogs -maxdepth 1 -type f -print | wc -l || :)+0))" || :; } 2>/dev/null + if [ "${_logfiles:-0}" -ge 50 ]; then + >.needsgc + return 0 + fi + # Truly git gc only checks the number of objects in the objects/17 directory + # We check for -ge 10 which should make the probability of having more than + # 5120 (20*256) loose objects present when there are less than 10 in + # objects/17 vanishingly small (20 is the threshold we use for pack files) + _objfiles= + ! [ -d objects/17 ] || + { _objfiles="$(($(find -L objects/17 -type f -name "$octet19*" -print | wc -l || :)+0))" || :; } 2>/dev/null + if [ "${_objfiles:-0}" -ge 10 ]; then + >.needsgc + return 0 + fi +} + # A well-known UTF-8 locale is required for some of the fast-import providers # in order to avoid mangling characters. Ideally we could use "POSIX.UTF-8" # but that is not reliably UTF-8 but rather usually US-ASCII. -- 2.11.4.GIT