3 # Keep track of the last time we modified the object store
5 # Beware, we MAY be running in a chroot!
9 var_xargs_r
=@var_xargs_r@
12 if [ -x @perlbin@
]; then
13 # We are NOT inside the chroot
15 list_packs
() { command "$basedir/bin/list_packs" "$@"; }
18 # Some platforms' broken xargs runs the command always at least once even if
19 # there's no input unless given a special option. Automatically supply the
20 # option on those platforms by providing an xargs function.
21 xargs() { command xargs $var_xargs_r "$@"; }
23 git config gitweb.lastreceive
"$(date '+%a, %d %b %Y %T %z')"
25 # Read the incoming refs and freshen old loose objects
26 # If we waited until post-receive a gc could have already nuked them
27 # We freshen the new ref in case it's being resurrected to protect it from gc
28 # We probably do not need to do it for new refs as Git tries to do that,
29 # but since we're already doing it for old refs (which Git does not do),
30 # it's almost no extra work for new refs, just in case. We also attempt
31 # to make all packs user and group writable so they can be touched later.
33 octet
='[0-9a-f][0-9a-f]'
34 octet4
="$octet$octet$octet$octet"
35 octet20
="$octet4$octet4$octet4$octet4$octet4"
37 find objects
/pack
-maxdepth 1 -type f \
! -perm -ug+w \
38 -name "pack-$octet20.pack" -print0 | \
42 # Trigger a mini-gc if there are at least 20 packs present.
43 # Our current pack that contains this push's data will have a .keep while
44 # this hook is running so we do not use --exclude-keep here under the
45 # assumption that by the time a mini-gc starts the .keep will have been
46 # removed. If not, that's okay too, it just means the current pack will
47 # not take part in the mini-gc and will have to wait for the next one.
48 # The mini-gc code contains the logic to sort out small packs vs. non-small
49 # packs and which should be combined in what order so we do not need to
50 # do any more complicated testing here.
51 if ! [ -e .needsgc
]; then
53 { packs
="$(list_packs --quiet --count --exclude-no-idx objects/pack || :)" ||
:; } 2>/dev
/null
54 if [ -n "$packs" ] && [ "$packs" -ge 20 ]; then
59 while read -r old new ref
; do
62 if [ "$old" != "0000000000000000000000000000000000000000" ]; then
63 # freshen mod time on recently unref'd loose objects
66 oldp
="objects/$shard/$fn"
68 if [ "$new" != "0000000000000000000000000000000000000000" ]; then
69 # prevent imminent pruning of a ref being resurrected
72 newp
="objects/$shard/$fn"
74 chmod ug
+w
$oldp $newp 2>/dev
/null ||
:
75 touch -c $oldp $newp 2>/dev
/null ||
: