From 3bc17a8a776df4884bb8bc6882da1bb8c3fa3409 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 9 May 2016 00:53:23 -0700 Subject: [PATCH] hooks/pre-receive: set .needsgc when many packs are present Signed-off-by: Kyle J. McKay --- hooks/pre-receive | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hooks/pre-receive b/hooks/pre-receive index 50eb2ac..7c66498 100755 --- a/hooks/pre-receive +++ b/hooks/pre-receive @@ -7,6 +7,13 @@ set -e var_xargs_r=@var_xargs_r@ +umask 002 + +if [ -x @perlbin@ ]; then + # We are NOT inside the chroot + basedir=@basedir@ + list_packs() { command "$basedir/bin/list_packs" "$@"; } +fi # Some platforms' broken xargs runs the command always at least once even if # there's no input unless given a special option. Automatically supply the @@ -32,6 +39,22 @@ octet20="$octet4$octet4$octet4$octet4$octet4" xargs -0 chmod ug+w } 2>/dev/null || : +# Trigger a mini-gc if there are at least 20 packs present. +# Our current pack that contains this push's data will have a .keep while +# this hook is running so we do not use --exclude-keep here under the +# assumption that by the time a mini-gc starts the .keep will have been +# removed. If not, that's okay too, it just means the current pack will +# not take part in the mini-gc and will have to wait for the next one. +# The mini-gc code contains the logic to sort out small packs vs. non-small +# packs and which should be combined in what order so we do not need to +# do any more complicated testing here. +if ! [ -e .needsgc ]; then + packs="$(list_packs --quiet --count --exclude-no-idx objects/pack || :)" + if [ -n "$packs" ] && [ "$packs" -ge 20 ]; then + >.needsgc + fi +fi + while read -r old new ref; do oldp= newp= -- 2.11.4.GIT