3 # NOTE: additional options can be passed to git repack by specifying
4 # them after the project name, for example:
8 . @basedir@
/jobd
/gc-util-functions.sh
13 echo "Usage: gc.sh projname [extra-repack-args]" >&2
19 unset GIROCCO_SUPPRESS_AUTO_GC_UPDATE
20 .
"$cfg_basedir/jobd/maintain-auto-gc-hack.sh"
21 .
"$cfg_basedir/jobd/generate-auto-gc-update.sh"
22 GIROCCO_SUPPRESS_AUTO_GC_UPDATE
=1 && export GIROCCO_SUPPRESS_AUTO_GC_UPDATE
25 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
29 eval "$1="'$(( $# - 1 ))'
33 if _result
="$(kill -0 "$1" 2>&1)"; then
34 # process exists and we have permission to signal it
37 case "$_result" in *"not permitted"*)
38 # we do not have permission to signal the process
41 # process does not exist
46 # A .lock file should only exist for much less than a second.
47 # If we see a stale lock file (> 1h old), remove it and then,
48 # just in case, wait 30 seconds for any process whose .lock
49 # we might have just removed (it's racy) to finish doing what
50 # should take much less than a second to do.
51 _stalelock
="$(find -L "$1.lock
" -maxdepth 1 -mmin +60 -print 2>/dev/null)" ||
:
52 if [ -n "$_stalelock" ]; then
57 if (set -C; >"$1.lock") 2>/dev
/null
; then
62 [ "$_try" != "p" ] ||
sleep 1
64 # cannot create lock file
68 # The pre-receive script creates one ref log file per push but we want them to
69 # be coalesced into one ref log file per day. We are guaranteed that any files
70 # we find to coalesce are NOT currently being written to since they are always
71 # written first as temporary files and then moved into place. We attempt to
72 # transfer the most recent modification time to the coalesced log file which
73 # would step on its mod time if it were being written to directly, but if we
74 # find per-process ref log files then it must be a push project and the only
75 # thing that would write directly to the main per-day log file would be a
76 # mirror project so there's actually no conflict.
77 # Also, if the clock is wonky (or was futzed with) we may have both YYYYMMDD
78 # and YYYYMMDD.gz present in which case combine them into YYYYMMDD
80 [ -d reflogs
] ||
return 0
82 find -L reflogs
-maxdepth 1 -type f
-name "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" -print |
83 while read -r rname
; do
84 if [ -e "$rname.gz" ]; then
85 if [ -s "$rname" ]; then
86 # Presumably the .gz file must have been created before the non-gz
87 # file since it had to be uncompressed at some point therefore
88 # we need to append the non-gz contents to it but keep the non-gz
89 # contents timestamp so we rename to YYYYMMDD_ which will sort first
90 # and be picked up in the next step if we are interrupted in the middle.
91 # If a YYYYMMDD_ file already exists we append to it and transfer the
92 # timestamp. Finally we transfer the YYYYMMDD_ timestamp to the result
93 # and remove the YYYYMMDD_ temporary file leaving the result uncompressed.
94 if [ -e "${rname}_" ]; then
95 cat "$rname" >>"${rname}_"
96 touch -r "$rname" "${rname}_"
100 mv "$rname" "${rname}_"
102 gzip -d "$rname.gz" </dev
/null
103 [ -e "$rname" ] && ! [ -e "$rname.gz" ]
104 cat "${rname}_" >>"$rname"
105 touch -r "${rname}_" "$rname"
108 # Just remove the empty file to resolve the problem
113 find -L reflogs
-maxdepth 1 -type f
-name "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_*" -print | LC_ALL
=C
sort |
114 while read -r rname
; do
115 logname
="${rname%%_*}"
116 # If someone's been futzing with the date, the file we want to
117 # append to could already have been compressed, so we just uncompress
118 # it here. The previous block guarantees we do not have both a compressed
119 # and uncompressed version present at the same time.
120 if [ -e "$logname.gz" ]; then
121 gzip -d "$logname.gz" </dev
/null
122 [ -e "$logname" ] && ! [ -e "$logname.gz" ]
124 cat "$rname" >>"$logname"
125 touch -r "$rname" "$logname"
127 if [ -e "$rname" ]; then
129 echo "! [$proj] failed to remove $rname" >&2
130 exit 1 # will only exit subshell created by "|"
136 # Remove any files in reflogs that are older than $cfg_reflogs_lifetime days
138 [ -d reflogs
] ||
return 0
139 exp
="$(( ${cfg_reflogs_lifetime:-1} * 1440 ))"
140 [ $exp -gt 0 ] || exp
=1440
141 [ $exp -le 43200 ] || exp
=43200
142 find -L reflogs
-maxdepth 1 -type f
-mmin "+$exp" -exec rm -f '{}' + ||
:
145 # Compact any reflogs that are not today's UTC date unless a .gz version exists
147 [ -d reflogs
] ||
return 0
148 _td
="reflogs/$(TZ=UTC date '+%Y%m%d')"
149 find -L reflogs
-maxdepth 1 -type f
-name "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" -print |
150 while read -r rname
; do
151 [ "$rname" != "$_td" ] ||
continue
152 ! [ -e "$rname.gz" ] ||
continue
153 gzip -9 "$rname" </dev
/null
157 # return true if there's more than one objects/pack-<sha>.pack file or
158 # ANY sha-1 files in objects or
159 # there's one pack and it's not a normal pack name or
160 # there's one pack but not any refs
162 _packs
="$(find -L objects/pack -name "pre-auto-gc-
[12].pack
" -prune -o -name "*.pack
" -type f -print 2>/dev/null | head -n 2)"
163 vcnt _packscnt
$_packs
164 if [ $_packscnt -gt 1 ]; then
167 if [ $_packscnt -eq 1 ]; then
168 # the single pack name is in $_packs
169 _packs
="${_packs%.pack}"
170 _packs
="${_packs#objects/pack/}"
173 _packs
="${_packs#pack-}"
174 if [ "${#_packs}" -lt 40 ] ||
[ "${_packs#*[!0-9a-fA-F]}" != "$_packs" ]; then
175 # name not exclusively 40 or more hexadecimal digits makes it dirty
180 # abnormal name makes it dirty
185 _objs
=$
(find -L objects
/$octet -name "$octet19*" -type f
-print 2>/dev
/null |
head -n 1 | LC_ALL
=C
wc -l)
186 [ $_objs -eq 0 ] ||
return 0
187 [ $_packscnt -eq 1 ] ||
return 1
188 # we do this check last because it's potentially the most expensive;
189 # at this point we know we do not have any loose objects, but we do
190 # have one pack that's named "normally"; empty refs => dirty
194 # combine the input pack(s) into a new pack (or possibly packs if packSizeLimit set)
195 # input pack names are read from standard input one per line delimited by the first
196 # ':', ' ' or '\n' character on the line (which allows gfi-packs to be read directly)
197 # all arguments, if any, are passed to pack-objects as additional options
198 # returns non-zero on failure AND creates .gc_failed in that case
201 find -L objects
/pack
-maxdepth 1 -type f
-name '*.zap*' -exec rm -f '{}' + ||
:
202 run_combine_packs
--replace "$@" $packopts --all-progress-implied $quiet --non-empty ||
{
209 # if the current directory is_gfi_mirror then repack all packs listed in gfi-packs
211 [ -n "$gfi_mirror" ] ||
return 0
212 [ -d objects
/pack
] ||
{ rm -f gfi-packs
; return 0; }
213 progress
"~ [$proj] redeltifying poor quality git fast-import packs"
214 combine_packs
--ignore-missing --no-reuse-delta <gfi-packs
219 # pack any existing loose objects into a new _l.pack file then run prune-packed
220 # note that prune-packed is NOT run beforehand -- the caller must do that if needed
221 # loose objects need not be part of complete commits/trees as --weak-naming is used
222 pack_loose_objects
() {
223 _lpacks
="$(run_combine_packs </dev/null --names --loose --weak-naming --non-empty --all-progress-implied ${quiet:---progress} $packopts)"
224 if [ -n "$_lpacks" ]; then
225 # We need to identify these packs later so we don't combine_packs them
226 for _objpack
in $_lpacks; do
227 rename_pack
"objects/pack/pack-$_objpack" "objects/pack/pack-${_objpack}_l" ||
:
229 git prune-packed
$quiet
233 # combine small packs into larger pack(s)
234 # we avoid any _[lo], keep, bndl or bitmap packs
235 # if the optional argument is non-empty even a single small pack will be redeltad
236 combine_small_packs
() {
239 if [ -n "$1" ] && [ -n "$noreusedeltaopt" ]; then
242 _lpo
="--exclude-no-idx --exclude-keep --exclude-bitmap --exclude-bndl"
243 _lpo
="$_lpo --exclude-sfx _u --exclude-sfx _o --exclude-sfx _l"
244 _lpo
="$_lpo --quiet --object-limit $var_redelta_threshold objects/pack"
246 _cnt
="$(list_packs --count $_lpo)" ||
:
247 test "${_cnt:-0}" -ge $_minsmallpacks
249 [ -n "$_didprogress" ] ||
{
250 progress
"~ [$proj] combining small packs into a single larger pack"
253 _newp
="$(list_packs $_lpo | combine_packs --names $noreusedeltaopt)"
255 # be paranoid and exit the loop if we haven't reduced the number of packs
256 [ $_newc -lt $_cnt ] ||
break
262 # combine small _l packs into larger pack(s) using --weak-naming
263 # we avoid any non _l, keep, bndl or bitmap packs
264 # if the optional 2nd argument is non-empty even a single small pack will be redeltad
265 combine_small_loose_packs
() {
268 if [ -n "$1" ] && [ -n "$noreusedeltaopt" ]; then
271 _lpo
="--exclude-no-idx --exclude-keep --exclude-bitmap --exclude-bndl"
272 _lpo
="$_lpo --exclude-no-sfx _l"
273 _lpo
="$_lpo --quiet --object-limit $var_redelta_threshold objects/pack"
275 _cnt
="$(list_packs --count $_lpo)" ||
:
276 test "${_cnt:-0}" -ge $_minsmallpacks
278 [ -n "$_didprogress" ] ||
{
279 progress
"~ [$proj] combining small loose packs into a single larger pack"
282 _newp
="$(list_packs $_lpo | combine_packs --names --weak-naming $noreusedeltaopt)"
283 # We need to identify these packs later so we don't combine_packs them
284 for _objpack
in $_newp; do
285 rename_pack
"objects/pack/pack-$_objpack" "objects/pack/pack-${_objpack}_l" ||
:
288 # be paranoid and exit the loop if we haven't reduced the number of packs
289 [ $_newc -lt $_cnt ] ||
break
295 # Unfortunately, some fetch strategies (e.g. git-svn and non-smart HTTP) lack
296 # the ability to store newly fetched objects in a pack.
297 # However, the fetch code conveniently sets .needspack just before it fetches
298 # so that it's easy to find all the loose objects that have been fetched and
299 # combine them into a pack. The --no-reuse-delta option is meaningless here
300 # since everything to be packed is a loose object and therefore not a delta so
301 # deltification will always take place.
303 [ -f .needspack
] ||
return 0
305 mv -f .needspack .needspackgc
306 progress
"~ [$proj] combining fetched loose objects into a pack"
307 _newp
="$(find -L objects/$octet -maxdepth 1 -type f -newer .needspackgc -name "$octet19*" -print 2>/dev/null |
308 LC_ALL=C awk -F / '{print $2 $3}' |
309 run_combine_packs --objects --names $packopts --incremental --all-progress-implied $quiet --non-empty)" ||
{
310 # We used to fail gc here.
311 # Now, however, we just ignore the failure because we have
312 # another mechanism to handle loose objects and it's possible
313 # that the fetcher somehow brought in unconnected objects which
314 # would cause the above combine-packs to fail.
315 # By ignoring the failure and just removing the .needspack file
316 # the loose objects will be treated as "ordinary" loose objects
317 # and packed using the "--weak-naming" option which can handle
318 # broken connectivity.
319 # That's a better solution than just failing here or leaving
320 # .needspack behind to potentially continue to fail again and
324 if [ -n "$_newp" ]; then
325 # remove the now-redundant loose objects -- this is always safe
326 # even during a concurrent push because a reprepare_packed_git
327 # will be triggered if an object that should be there is not
328 # found thereby finding it in the new pack instead
329 git prune-packed
$quiet
334 # HEADSHA="$(pack_is_complete /full/path/to/some.pack /full/path/to/packed-refs "$(cat HEAD)")"
336 # Must have a matching .idx file and a non-empty packed-refs file
337 [ -s "${1%.pack}.idx" ] ||
return 1
338 [ -s "$2" ] ||
return 1
344 "ref: refs/"?
*|
"ref:refs/"?
*|
"refs/"?
*)
345 _headmatch
="${3#ref:}"
346 _headmatch
="${_headmatch# }"
347 _headmatchpat
="$(echo "$_headmatch" | LC_ALL=C sed -e 's/\([.$]\)/\\\1/g')"
348 _headsha
="$(LC_ALL=C grep -e "^
$octet20$hexdig* $_headmatchpat\$
" <"$2" |
349 LC_ALL=C cut -d ' ' -f 1)"
350 case "$_headsha" in $octet20*) :;; *)
358 rm -rf pack_is_complete_test
359 mkdir pack_is_complete_test
360 mkdir pack_is_complete_test
/refs
361 mkdir pack_is_complete_test
/objects
362 mkdir pack_is_complete_test
/objects
/pack
363 echo "$_headsha" >pack_is_complete_test
/HEAD
364 ln -s "$1" pack_is_complete_test
/objects
/pack
/
365 ln -s "${1%.pack}.idx" pack_is_complete_test
/objects
/pack
/
366 ln -s "$2" pack_is_complete_test
/packed-refs
367 _count
="$(git --git-dir=pack_is_complete_test rev-list --count --all 2>/dev/null)" ||
:
368 rm -rf pack_is_complete_test
369 [ -n "$_count" ] ||
return 1
370 [ "$_count" -gt 0 ] 2>/dev
/null ||
return 1
374 # On return a "$lockf" will have been created that must be removed when gc is done
376 # be compatibile with gc.pid file from newer Git releases
380 if [ "$(createlock "$lockf")" ]; then
382 # 1) less than 12 hours old
383 # 2) contains two fields (pid hostname) NO trailing NL
384 # 3) the hostname is different OR the pid is still alive
385 # then we exit as another active process is holding the lock
386 if [ "$(find -L "$lockf" -maxdepth 1 -mmin -720 -print 2>/dev/null)" ]; then
389 read -r apid ahost ajunk
<"$lockf" ||
:
390 if [ "$apid" ] && [ "$ahost" ]; then
391 if [ "$ahost" != "$hn" ] || pidactive
"$apid"; then
397 echo >&2 "[$proj] unable to create gc.pid.lock file"
400 if [ -n "$active" ]; then
402 echo >&2 "[$proj] gc already running on machine '$ahost' pid '$apid'"
405 printf "%s %s" "$$" "$hn" >"$lockf.lock"
406 chmod 0664 "$lockf.lock"
407 mv -f "$lockf.lock" "$lockf"
410 # Create a repack subdirectory such that running repack in it will pack the
411 # same things that a pack in the normal directory would except that the pack
412 # is guaranteed to be generated in an optimized order by adding a suitable
413 # synthesized ref in the refs/tags namespace (yes, pack-objects.c really does
414 # behave differently depending on the contents of the refs/tags namespace).
415 # Before calling this, pack-refs --all MUST be performed or the wrong pack
416 # will end up being made.
418 # If a ref deletion is pushed after making the repack subdir but before the
419 # the actual repack, the discarded objects will be packed -- no big deal,
420 # they'll get discarded the next time gc runs.
422 # If a fast-forward ref update is pushed after making the repack subdir but
423 # before the actual repack, it will be picked up and the new objects packed
424 # (subject to the normal git repack race about picking such updates up).
426 # If a non-fast-forward ref update is pushed after making the repack subdir but
427 # before the actual repack, it will be picked up like a fast-forward update but
428 # the discarded objects will be included like a ref deletion (until the next
429 # scheduled gc takes place).
431 # We retain a copy of the original packed-refs file as repack/packed-refs.orig
432 # If ref deletions come in while we're repacking, the original packed-refs
433 # file will be modified, but we'll still pack the deleted ref(s).
434 # If the packed-refs.orig file is used to create the bundle header we avoid
435 # a situation where the bundle contains a ref state that never actually
436 # existed in reality (for example a new branch is pushed and then an old
437 # branch deleted afterwards -- the deletion would show up in the bundle
438 # because it will cause the original packed-refs file to be re-written, but
439 # the new branch creation will not unless we do another pack-refs which might
440 # lead to having in incomplete bundle). Therefore we want to keep a copy of
441 # the original packed-refs file around. We do the same thing for HEAD.
443 # It's possible that the "objects" subdirectory is a symbolic link.
444 # Git does support this. However, during the repacking process, new packs
445 # will be created in repack/alt/pack and then moved into objects/pack.
446 # In order for this to work seemlessly, they must both be on the same
447 # filesystem. But when objects (or even objects/pack) is a symbolic link they
448 # might not be. For this reason a "repack" subdirectory is created under
449 # objects/pack and the repack/alt/pack directory symbolicly linked to it.
451 # Git allows not just HEAD to be a symbolic-ref, but any ref anywhere in the
452 # refs namespace. We are concerned about ref name collisions and getting the
453 # right tag set to get an optimal pack. We can safely duplicate the ref space
454 # under refs/heads, refs/notes and refs/remotes without any risk of unwanted
455 # collisions and this will likely make over 99%+ of all symbolic refs found
456 # in the wild work properly. Girocco itself never creates any symbolic refs
457 # inside the refs namespace; this is a nod to simultaneously using a Girocco
458 # repository for other purposes.
460 ! [ -d repack
] ||
rm -rf repack
461 ! [ -d repack
] ||
{ echo >&2 "[$proj] cannot remove repack subdirectory"; exit 1; }
462 [ -d objects
/pack
] || mkdir
-p objects
/pack
463 ! [ -d objects
/pack
/repack
] ||
rm -rf objects
/pack
/repack
464 ! [ -d objects
/pack
/repack
] ||
{ echo >&2 "[$proj] cannot remove objects/pack/repack subdirectory"; exit 1; }
465 mkdir repack repack
/refs repack
/alt objects
/pack
/repack
466 [ -d info
] || mkdir info
467 ln -s ..
/config repack
/config
468 ln -s ..
/info repack
/info
469 ln -s ..
/objects repack
/objects
470 ln -s "$PWD/objects/pack/repack" repack
/alt
/pack
471 ln -s ..
/..
/refs repack
/refs
/refs
472 ! [ -d logs
] ||
ln -s ..
/logs repack
/logs
473 ! [ -d worktrees
] ||
ln -s ..
/worktrees repack
/worktrees
474 _lines
=$
(( $
(LC_ALL
=C
wc -l <packed-refs
) ))
475 cat HEAD
>repack
/HEAD.orig
476 >repack
/packed-refs.extra
478 cat packed-refs
>repack
/packed-refs.orig
479 if [ $
(LC_ALL
=C
wc -l <repack
/packed-refs.orig
) -ne "$_lines" ]; then
480 echo >&2 "[$proj] error: make_repack_dir failed original packed-refs line count sanity check"
483 if [ "${cfg_fetch_stash_refs:-0}" = "0" ]; then
484 # migrate any refs/stash or refs/tgstash lines to repack/packed-refs.extra
485 <repack
/packed-refs.orig LC_ALL
=C
awk -v xtra
="repack/packed-refs.extra" '
486 BEGIN { peeling = 0 }
487 NR == 1 && /^#/ { print; next; }
488 peeling && /^\^/ { print >>xtra; next; }
489 /^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]+ refs\/(stash|tgstash)(\/|$)/ {
494 { peeling = 0; print; }
495 ' >repack
/packed-refs.new
496 _xtralines
="$(( $(LC_ALL=C wc -l <repack/packed-refs.extra) + 0 ))"
497 _newlines
="$(( $(LC_ALL=C wc -l <repack/packed-refs.new) + 0 ))"
498 if [ "$(( $_newlines + $_xtralines ))" -ne "$_lines" ]; then
499 echo >&2 "[$proj] error: make_repack_dir failed packed-refs.extra line count sanity check"
502 mv -f repack
/packed-refs.new repack
/packed-refs.orig
505 # Note: Git v1.5.0 introduced the "# pack-refs with:" header line for the packed-refs file
506 sed '/^# pack-refs/d; s, refs/, refs/!/,' <repack
/packed-refs.orig
>repack
/packed-refs
508 headref
="$(git rev-parse --verify --quiet HEAD)" ||
:
509 if [ -n "$headref" ]; then
510 echo "$headref refs/!=/HEAD" >>repack
/packed-refs
511 echo "$headref refs/heads/!" >>repack
/packed-refs
512 nohead
='\, refs/heads/!$,d; '
513 _lines
=$
(( $_lines + 2 ))
515 if [ $
(( $
(LC_ALL
=C
wc -l <repack
/packed-refs
) + 1 )) -ne "$_lines" ]; then
516 echo >&2 "[$proj] error: make_repack_dir failed packed-refs initial line count sanity check"
519 sed -n "$nohead"'\, refs/heads/,p; \, refs/notes/,p; \, refs/remotes/,p' <repack
/packed-refs.orig
>>repack
/packed-refs
520 _newlines
="$(( $(LC_ALL=C wc -l <repack/packed-refs) ))"
521 if [ $
(( $_newlines + 1 )) -lt "$_lines" ]; then
522 echo >&2 "[$proj] error: make_repack_dir failed packed-refs extra line count sanity check"
526 optref
="$(git rev-list -n 1 --all 2>/dev/null)" ||
:
527 if [ -n "$optref" ]; then
528 echo "$optref refs/tags/!" >>repack
/packed-refs
529 _lines
=$
(( $_lines + 1 ))
530 echo "$optref" >repack
/HEAD
532 cat HEAD
>repack
/HEAD
534 if [ $
(LC_ALL
=C
wc -l <repack
/packed-refs
) -ne "$_lines" ]; then
535 echo >&2 "[$proj] error: make_repack_dir failed packed-refs line count sanity check"
540 # Remove any crud that's been left behind by interrupted operations
541 # that did not clean up after themselves
543 # Remove any existing FETCH_HEAD
544 # There can only be a FETCH_HEAD if we've been fetching, not if we've been
545 # receiving pushes (those never create a FETCH_HEAD).
546 # And if we're fetching because we're a mirror, we know we're not fetching right
547 # now since jobd.pl never runs a project's fetch simultaneously with its gc.
548 # Therefore any existing FETCH_HEAD is junk. And it may be many megabytes if
549 # there were a lot of refs.
552 # remove any existing pack_is_complete_test or repack subdirectories
553 # If either exists when this function is called it's crud
554 rm -rf pack_is_complete_test repack objects
/pack
/repack
556 # Remove any stale pack remnants that are more than an hour old.
557 # Stale pack fragments are defined as any pack-<sha1>.ext where .ext is NOT
558 # .pack AND the corresponding .pack DOES NOT exist. A bunch of stale
559 # pack-<sha1>.idx files without their corresponding .pack files are worthless
560 # and just waste space. Normally there shouldn't be any remnants but actually
561 # this can happen when things are interrupted at just the wrong time.
562 # Note that the objects/pack directory is created by git init and should
564 find -L objects
/pack
-maxdepth 1 -type f
-mmin +60 -name "pack-$octet20*.?*" -print |
565 LC_ALL
=C
sed -e 's/^objects\/pack\/pack-//; s/\..*$//' | LC_ALL
=C
sort -u |
566 while read packsha
; do
567 ! [ -e "objects/pack/pack-$packsha.pack" ] ||
continue
568 rm -f "objects/pack/pack-$packsha".?
*
571 # Remove any stale tmp reflogs files that are more than one hour old.
572 # Since they are created only while the pre-receive hook is running and
573 # all it does is process a bunch of refs passed to it on standard input
574 # it's inconceivable that it would ever take as much as an hour to run.
575 if [ -d reflogs
]; then
576 find -L reflogs
-maxdepth 1 -type f
-mmin +60 -name "tmp_*" -exec rm -f '{}' + ||
:
579 # Remove any stale object tmp_obj_* files that are more than 3 hours old.
580 # Really these files should only exist very briefly so there shouldn't be any
581 # but things happen that can end up leaving them behind.
582 find -L objects
/$octet -maxdepth 1 -type f
-mmin +180 -name "tmp_obj_?*" -exec rm -f '{}' + 2>/dev
/null ||
:
584 # Remove any stale pack .keep files that are more than 12 hours old.
585 # We don't do anything to create any permanent pack .keep files, so they must
586 # be remnants from some failed push or something. Removing the .keep will
587 # allow the pack to be properly repacked.
588 find -L objects
/pack
-maxdepth 1 -type f
-mmin +720 -name "pack-$octet20*.keep" -exec rm -f '{}' + ||
:
590 # Remove any stale tmp_pack_*, tmp_idx_*, tmp_bitmap_*, packtmp-* or .tmp-*-pack* files
591 # that are more than 12 hours old.
592 find -L objects
/pack
-maxdepth 1 -type f
-mmin +720 \
( \
593 -name "tmp_pack_?*" -o -name "tmp_idx_?*" -o -name "tmp_bitmap_?*" -o \
594 -name "packtmp-?*" -o -name ".tmp-?*-pack*" \
595 \
) -exec rm -f '{}' + ||
:
597 # Remove any stale incoming-* object quarantine directories that are
598 # more than 12 hours old. These are new with Git >= 2.11.0.
599 find -L objects
-maxdepth 1 -type d
-name 'incoming-?*' -mmin +720 \
600 -exec rm -rf '{}' + ||
:
602 # Remove any stale shallow_* files that are more than 12 hours old.
603 # These can be left behind by Git >= 1.8.4.2 and < 2.0.0 when a client
604 # requests a shallow clone. Also discard stale .refs-temp* and
605 # .refs-new* files at the same time.
606 find -L .
-maxdepth 1 -type f
-mmin +720 \
( \
607 -name "shallow_?*" -o -name ".refs-temp*" -o -name ".refs-new*" \
608 \
) -exec rm -f '{}' + ||
:
610 # Remove any stale cmbnpcks-* dirs that are more than 12 hours old.
611 # These can be left behind by abnormal exits (e.g. power failure).
612 find -L .
-maxdepth 1 -type d
-mmin +720 -name "cmbnpcks-?*" \
613 -exec rm -rf '{}' + ||
:
615 # Remove any stale *.temp files in the objects area that are more than 12 hours old.
616 # This can be stale sha1.temp, or stale *.pack.temp so we kill all stale *.temp.
617 find -L objects
-type f
-mmin +720 -name "*.temp" -exec rm -f '{}' + ||
:
619 # Remove any stale *.lock files in the htmlcache area that might have been left
620 # behind after an abnormal exit during an attempt to update a cached file and
621 # are more than 1 hour old.
622 ! [ -d htmlcache
] ||
find -L htmlcache
-type f
-mmin +60 -name "*.lock" -exec rm -f '{}' + ||
:
624 # Remove any stale git-svn temp files that are more than 12 hours old.
625 # The git-svn process creates temp files with random 10 character names
626 # in the root of $GIT_DIR. Unfortunately they do not have a recognizable
627 # prefix, so we just have to kill any files with a 10-character name. We
628 # do this only for git-svn mirrors. All characters are chosen from
629 # [A-Za-z0-9_] so we can at least check that and fortunately the only
630 # collision is 'FETCH_HEAD' but that shouldn't matter.
631 # There may also be temp files with a Git_ prefix as well.
632 if [ -n "$svn_mirror" ]; then
633 _randchar
='[A-Za-z0-9_]'
634 _randchar2
="$_randchar$_randchar"
635 _randchar4
="$_randchar2$_randchar2"
636 _randchar10
="$_randchar4$_randchar4$_randchar2"
637 find -L .
-maxdepth 1 -type f
-mmin +720 -name "$_randchar10" -exec rm -f '{}' + ||
:
638 find -L .
-maxdepth 1 -type f
-mmin +720 -name "Git_*" -exec rm -f '{}' + ||
:
641 # Remove any stale fast_import_crash_<pid> files that are more than 3 days old.
642 if [ -n "$gfi_mirror" ]; then
643 find -L .
-maxdepth 1 -type f
-mmin +4320 -name "fast_import_crash_?*" -exec rm -f '{}' + ||
:
646 # Remove any stale core or *.core or core.* files that are more than 3 days old.
647 find -L .
-maxdepth 1 -type f
-mmin +4320 \
( -name "core" -o -name "*.core" -o -name "core.*" \
) \
648 -exec rm -f '{}' + ||
:
652 ## Garbage Collection Types
654 ## There are two kinds of possible garbage collection (gc) operations:
656 ## 1. A normal, full gc
659 ## If the full garbage collection interval has expired (or gc has never been
660 ## run), then a normal, full gc will take place. Otherwise, a "mini" gc will
661 ## take place if the file .needsgc exists.
663 ## A "mini" gc is similar to "git gc --auto" in that it may not end up actually
664 ## doing anything unless the right conditions are present so it's not a burden
665 ## to run it often. If the file .needsgc exists, a "mini" gc will occur at
666 ## the next opportunity.
668 ## See the docs/technical/gc.txt and docs/technical/gc-mini.txt files for more
669 ## of the gory details of how garbage collection is performed.
671 ## Note, however, that the .nogc file suppresses ALL gc activity (normal or mini).
676 cd "$cfg_reporoot/$proj.git"
677 [ -d objects
/pack
] ||
{ rm -f gfi-packs
; mkdir
-p objects
/pack
; }
678 mirror_url
="$(get_mirror_url)" ||
:
680 ! is_svn_mirror_url
"$mirror_url" || svn_mirror
=1
682 if [ -f gfi-packs
] && [ -s gfi-packs
] && is_gfi_mirror_url
"$mirror_url"; then
686 # If git config --bool --get girocco.redelta is explicitly false then automatic
687 # redelta when there are less than $var_redelta_threshold objects will be suppressed.
688 # On the other hand, if git config --get girocco.redelta is "always" then, on a full
689 # gc only, for the final repack, deltas will always be recomputed.
690 # This can be set on a per-project basis to avoid unusual pathological gc behavior.
691 # Setting this will hurt efficiency of the affected repository.
692 # Note that fast-import packs ALWAYS get new deltas regardless of this setting.
693 noreusedeltaopt
="--no-reuse-delta"
694 [ "$(git config --bool --get girocco.redelta 2>/dev/null || :)" != "false" ] || noreusedeltaopt
=
696 [ "$(git config --get girocco.redelta 2>/dev/null || :)" != "always" ] || alwaysredelta
=1
698 # Extract any -f or -F or --no-reuse-object or --no-reuse-delta options
699 # to be compatible with the old and new gc.sh versions and avoid ugly argument
700 # duplication in process lists at the same time
701 # Any options found will override the "girocco.redelta" setting
704 while [ $idx -gt 0 ]; do
713 -F|
--no-reuse-object)
721 printf >&2 '%s\n' "bad non-option argument: $opt"
722 echo >&2 "(Did you perhaps intend to use a --xxx=yyy form?)"
725 [ -z "$opt" ] ||
set -- "$@" "$opt"
727 if [ -n "$alwaysredelta" ]; then
728 noreusedeltaopt
="--no-reuse-delta"
729 [ -z "$recompress" ] || noreusedeltaopt
="--no-reuse-object"
732 trap 'e=$?; rm -f .gc_in_progress; if [ $e != 0 ]; then echo "gc failed dir: $PWD" >&2; fi' EXIT
736 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
737 datefmt
='+%a, %d %b %Y %T %z'
740 if [ "${force_gc:-0}" = "0" ] && check_interval lastgc
$cfg_min_gc_interval; then
741 if [ -e .needsgc
]; then
744 progress
"= [$proj] garbage check skip (last at $(config_get lastgc))"
748 if [ -e .nogc
]; then
749 progress
"x [$proj] garbage check disabled"
752 if ! [ -e .nofetch
] && [ -e .clone_in_progress
] && ! [ -e .clone_failed
]; then
753 progress
"x [$proj] garbage check disabled (clone in progress)"
756 if [ -z "$isminigc" ] && [ -e .delaygc
] && [ -e .needsgc
]; then
757 # Eligible for a full gc but .delaygc is set so it would be skipped
758 # However .needsgc is also set so transform it into a mini instead
760 progress
"~ [$proj] garbage check delayed but checking mini because .needsgc"
763 if [ -n "$isminigc" ]; then
764 # Perform a "mini" gc
765 # Note that .delaygc is ignored here as that's only intended for full gc
767 rm -f .allowgc .needsgc
768 rm -f objects
/pack
/pack-
*_
[rful
].keep
773 maintain_auto_gc_hack
774 generate_auto_gc_update
776 if [ -f .needspack
]; then
778 progress
"+ [$proj] mini garbage check ($(date))"
781 if [ -z "$cfg_delay_gfi_redelta" ] && [ -n "$gfi_mirror" ]; then
782 # $Girocco::Config::delay_gfi_redelta is false, force redeltification now
783 if [ -z "$miniactive" ]; then
785 progress
"+ [$proj] mini garbage check ($(date))"
789 if lotsa_loose_objects
; then
790 if [ -z "$miniactive" ]; then
792 progress
"+ [$proj] mini garbage check ($(date))"
796 # If there aren't at least 10 non-keep, non-bitmap, non-bndl packs then
797 # don't actually process them yet
798 lpo
="--exclude-no-idx --exclude-keep --exclude-bitmap --exclude-bndl --quiet"
799 packcnt
="$(list_packs --count $lpo objects/pack)" ||
:
800 if [ "${packcnt:-0}" -ge 10 ]; then
801 if [ -z "$miniactive" ]; then
803 progress
"+ [$proj] mini garbage check ($(date))"
805 # if we have at least 10 packs go ahead and pack all refs now too
806 git pack-refs
--all --prune
807 if [ -n "$gfi_mirror" ]; then
809 packcnt
="$(list_packs --count $lpo objects/pack)" ||
:
811 # if repack_gfi_packs dropped the pack count to < 10 don't combine
812 if [ "${packcnt:-0}" -ge 10 ]; then
814 combine_small_loose_packs
815 packcnt
="$(list_packs --count $lpo objects/pack)" ||
:
817 # if we still have more than 10 packs trigger a full gc
818 if [ "${packcnt:-0}" -ge 10 ]; then
819 # We shouldn't be in a .delaygc state at this point, but if
820 # we are then nuke it because we really need a full gc now
822 git config
--unset gitweb.lastgc
824 git update-server-info
# just in case
825 progress
"- [$proj] mini garbage check triggering full gc too many packs ($(date))"
830 if [ -n "$miniactive" ]; then
831 git update-server-info
832 progress
"- [$proj] mini garbage check ($(date))"
834 progress
"= [$proj] mini garbage check nothing but crud removal to do ($(date))"
839 # Avoid unnecessary garbage collections:
840 # 1. If lastreceive is set and is older than lastgc
842 # 2. We are not a fork (is_empty_alternates_file) -OR- lastparentgc is older than lastgc
844 # If lastgc is NOT set or lastreceive is NOT set we MUST run gc
845 # If we are a fork and lastparentgc is NOT set we MUST run gc
847 # If the repo is dirty after removing any crud we MUST run gc
849 gcstart
="$(date "$datefmt")"
852 is_empty_alternates_file objects
/info
/alternates || isfork
=1
854 [ -z "$isfork" ] || lastparentgcsecs
="$(config_get_date_seconds lastparentgc)" ||
:
856 if lastreceivesecs
="$(config_get_date_seconds lastreceive)" &&
857 [ "${force_gc:-0}" = "0" ] &&
858 lastgcsecs
="$(config_get_date_seconds lastgc)" &&
859 [ $lastreceivesecs -lt $lastgcsecs ]; then
860 # We've run gc since we last received, so maybe we can skip,
861 # check if not fork or fork and lastparentgc < lastgc
862 if [ -n "$isfork" ]; then
863 if [ -n "$lastparentgcsecs" ] &&
864 [ $lastparentgcsecs -lt $lastgcsecs ]; then
865 # We've run gc since our parent ran gc so we can skip
869 # We don't have any alternates (we're not a forK) so we can skip
874 # Prevent any other simultaneous gc operations
877 # At this point, if .allowgc or .gc_failed exists, it's now crud to be removed
878 rm -f .allowgc .gc_failed
880 # Ideally we would do this in post-receive, but that would mean duplicating the
881 # logic so it's available in the chroot jail and that's highly undesirable
882 # Instead, since the first gc will be triggered immediately following the first
883 # push, we do the check here as it's quick and harmless if HEAD is already valid
884 check_and_set_head ||
:
886 # Always get rid of crud
889 # Always perform reflogs maintenance
894 # Always maintain auto gc hack
895 maintain_auto_gc_hack
896 generate_auto_gc_update
898 # Run 'git svn gc' now for svn mirrors
899 if [ -n "$svn_mirror" ]; then
903 # Skip the actual gc if .delaygc is set
904 if [ -e .delaygc
]; then
905 progress
"x [$proj] garbage check delayed (except for crud removal)"
910 # Do not skip gc if the repo is dirty
911 if [ -n "$skipgc" ] && ! is_dirty
; then
912 progress
"= [$proj] garbage check nothing but crud removal to do ($(date))"
913 config_set lastgc
"$gcstart"
919 if [ -n "$isfork" ] && [ -z "$lastparentgcsecs" ]; then
920 # set lastparentgc and then update gcstart to be at least 1 second later
921 config_set lastparentgc
"$gcstart"
924 if [ -z "$lastreceivesecs" ]; then
925 # set lastreceive and then update gcstart to be at least 1 second later
926 config_set lastreceive
"$gcstart"
929 if [ -n "$bumptime" ]; then
931 gcstart
="$(date "$datefmt")"
934 progress
"+ [$proj] garbage check ($(date))"
937 [ -z "$alwaysredelta" ] || newdeltas
="$noreusedeltaopt"
938 if [ -z "$newdeltas" ] && [ -n "$gfi_mirror" ]; then
939 if [ $
(list_packs
--exclude-no-idx --count objects
/pack
) -le \
940 $
(list_packs
--exclude-no-idx --count --quiet --only gfi-packs
) ]; then
941 # Don't bother with repack_gfi_packs since everything's being repacked
942 newdeltas
="--no-reuse-delta"
945 if [ -z "$newdeltas" ] && [ -n "$noreusedeltaopt" ] &&
946 [ $
(list_packs
--all --exclude-no-idx --count-objects objects
/pack
) -le $var_redelta_threshold ]; then
947 # There aren't enough objects to worry about so just redelta to get the best pack
948 newdeltas
="--no-reuse-delta"
950 if [ -z "$newdeltas" ]; then
951 # Since we're not going to recompute deltas overall, we need to do the
952 # "mini" maintenance so that we can get more optimal deltas
953 [ -z "$noreusedeltaopt" ] || make_needs_pack
955 force_single_pack_redelta
=
956 [ -n "$gfi_mirror" ] ||
[ -n "$svn_mirror" ] || force_single_pack_redelta
=1
957 [ -z "$noreusedeltaopt" ] || combine_small_packs
$force_single_pack_redelta
958 [ -z "$noreusedeltaopt" ] || combine_small_loose_packs
$force_single_pack_redelta
962 ## Safe Pruning In Forks
964 ## We are about to perform garbage collection. We do NOT use the "git gc" or
965 ## the "git repack" commands directly as they do not provide enough control over
966 ## the fine details. However, we DO maintain a "gc.pid" file during our garbage
967 ## collection so that a simultaneous "git gc" by an administrator will be
968 ## blocked (and similarly we refuse to start garbage collection if we cannot
969 ## create the "gc.pid" file).
971 ## When we say "gc" in the below description we are referring to our "gc.sh"
972 ## script, NOT the "git gc" command.
974 ## If the project we are running garbage collection (gc) on has any forks we
975 ## must be careful not to remove any objects that while no longer referenced by
976 ## this project (the parent) are still referenced by one or more forks (the
977 ## children) otherwise the children will become corrupt and we can't abide
980 ## One way to accomplish this is to simply hard-link all currently existing
981 ## loose objects and packs in the parent into all the children that refer to the
982 ## parent (via a line in their objects/info/alternates file) before beginning
983 ## the gc operation and then relying on a subsequent gc in the child to clean up
984 ## any excess objects/packs. We used to use this strategy but it's very
985 ## inefficient because:
987 ## 1. The disk space used by the old pack(s)/object(s) will not be reclaimed
988 ## until all children (and their children, if any) run gc by which time
989 ## it's quite possible the topmost parent will have run gc again and
990 ## hard-linked yet another old pack down to its children (not to mention
993 ## 2. When using the "-A" option with "git repack", any new objects in the
994 ## parent that are not referenced by children will continually get
995 ## exploded out of the hard-linked pack in the children whenever the
998 ## 3. To avoid suboptimal and/or unnecessarily many packs being hard-linked
999 ## into child forks, we must run the "mini" gc maintenance before we
1000 ## perform the hard-linking into the children which provides yet another
1001 ## source of inefficiency.
1003 ## While we were still using the "-A" option to "git repack" (that was not
1004 ## always the case) to guarantee we can access old ref values for long enough
1005 ## to send out a meaningful mail.sh notification, another, more efficient,
1006 ## option became available to prevent corruption of child forks that continue
1007 ## to refer to objects that are no longer reachable from any ref in the parent.
1009 ## The only things that need be copied (or hard-linked) into the child fork(s)
1010 ## are those objects that have become unreachable from any ref in the parent.
1012 ## When we were using the "git repack -A -d" + "git prune --expire=1.day.ago"
1013 ## technique, the only objects that could ever be removed were loose objects
1014 ## that "git prune" determined were expired. In that case, loose objects were
1015 ## all that need be hard-linked down to child forks in order to avoid
1016 ## corruption of any child fork(s).
1018 ## The "git repack -A -d" + "git prune --expire=1.day.ago" + hard-linking loose
1019 ## objects to child forks technique remains fundamentally sound from the
1020 ## perspective of supporting simultaneous gc and push and keeping newly
1021 ## unreachable objects around long enough to be sure we can send out meaningful
1022 ## ref change notifications and never corrupting any child forks and never
1023 ## persisting the lifetime of large old packs containing mostly duplicate or
1024 ## unreachable objects as gc percolates through a project's entire fork tree.
1026 ## However, that technique suffers from one potential prodigious pitfall.
1028 ## Unreachable objects come flying out of their packs to splatter all over the
1029 ## objects subdirectories possibly creating a huge, inefficient mess.
1031 ## Often this is not an issue. Even with a lot of rebasing going on, usually
1032 ## the only objects that will splatter are some commits, trees and the odd blob
1033 ## here and there. Not enough to be overly concerned about.
1035 ## However, for the reppository that frequently experiences a lot of non-fast-
1036 ## forward updates and/or outright ref deletion, the number of objects suddenly
1037 ## popping out of their packs at "git repack -A -d" time can be overwhelming.
1039 ## To avoid this issue we now use a four phase pack creation strategy.
1040 ## This will result in creation of up to four packs (instead of at most one).
1042 ## I. A complete pack (with bitmaps if appropriate) gets created including
1043 ## only "reachable" objects from all refs/... refs plus HEAD. This will
1044 ## also serve as the virtual bundle for the repository.
1046 ## II. A pack of recently-became-unreachable objects and friends is created.
1047 ## (The "friends" are ref logs, linked working tree HEADs and indicies.)
1048 ## Because both the pre-receive and update.sh script record all ref
1049 ## changes we can easily choose the cut off point for "recently".
1050 ## It is only the fact we maintain those logs in the reflogs subdirectory
1051 ## that allows this step to be possible.
1053 ## III. If the repository has any forks with a non-zero length alternates file,
1054 ## yet another pack of "--keep-unreachable" objects is generated that will
1055 ## not actually be kept in the parent, but hard-linked into all the forks.
1057 ## IV. Finally, after running "git prune-packed", any remaining loose objects
1058 ## are migrated into a pack of their own.
1060 ## We then remove any non-.keep packs that existed before we started the
1061 ## process being careful to keep any same-pack pushes for the "Push Pack Redux"
1062 ## race condition (see docs/technical/gc.txt).
1064 ## By using "git pack-objects" directly we are able to accomplish this with
1065 ## very little additional effort.
1067 ## The packs produced by (III) are treated almost like ".keep" packs by child
1068 ## forks in that the objects in them are never repacked into any other
1069 ## "--keep-unreachable" packs (but they can migrate into phase I or II packs)
1070 ## and those phase III packs are then hard-linked into any grandchild forks.
1072 ## This avoids the space explosion that could occur if each fork level ended
1073 ## up duplicating the "--keep-unreachable" pack space by repacking those
1074 ## objects (essentially breaking the hard-link to the single copy of those
1077 ## While it is true that each level of forks could potentially add yet another
1078 ## phase III pack to be hard-linked down to its children, such packs will only
1079 ## include unreachable objects not already in any phase III packs that were
1080 ## received from the parent.
1082 ## The space for the phase III packs will not be reclaimed until the gc
1083 ## finishes percolating through the entire "fork tree" of a project.
1085 ## This is not much different than the "git repack -A -d" situation where
1086 ## all the loose objects are hard-linked down into child forks. In that
1087 ## case forks that actually need any of those objects could gradually reduce
1088 ## the number of objects hard-linked into deeper fork levels.
1090 ## The difference with a phase III "--keep-unreachable" pack is that there
1091 ## cannot be any gradual reduction like that since it would require repacking
1092 ## the pack and breaking the hard-link thereby increasing storage space. The
1093 ## storage will instead always be reclaimed all at once when all of the
1094 ## projects in the "fork tree" complete their gc.
1096 ## However, the belief is that the huge space win by having all the
1097 ## unreachable objects packed up together far eclipses (when many objects are
1098 ## involved, the single-pack version can end up using 1/20th or less of the
1099 ## disk space compared to having them all as loose objects) any brief minor
1100 ## space savings that might occur under the "git repack -A -d" loose object
1101 ## system prior to the gc collection completing for all the projects in the
1106 ## utility functions
1110 find -L "$1" -maxdepth 1 -type f
! -perm -ug+w \
1111 -name "pack-$octet20*.pack" -exec chmod ug
+w
'{}' + ||
:
1115 if [ -s "$1" ]; then
1117 export GIT_INDEX_FILE
1118 git write-tree
2>/dev
/null ||
:
1119 unset GIT_INDEX_FILE
1123 get_detached_head
() {
1124 if [ -s "$1" ] && read -r _head
<"$1" 2>/dev
/null
; then
1125 case "$_head" in $octet20*)
1131 # single argument must be a top-level GIT_DIR
1132 # output will be (one per line, zero or more lines) full hash
1133 # values (i.e. 40 or more hex digits) from possible detached head
1134 # "single level" refs (e.g. "FETCH_HEAD" "MERGE_HEAD" etc.) from
1135 # files in the specified directory that have a "suitable" name and
1136 # have a length >= 40 and <= 1000 where EVERY line in a file MUST
1137 # match a 40 digit (or longer) hex string or that file will be ignored.
1138 # In a nod to Git each line first has any tab and anything following truncated.
1139 # NO sorting NOR "uniq"ing NOR "--batch-check"ing is performed on the output.
1140 # Also note that "HEAD" is NOT EXCLUDED and if detached will be output!
1141 get_detached_friends
() {
1142 if [ -n "$1" ] && [ -d "$1" ]; then
1143 LC_ALL
=C
find -H "$1" -maxdepth 1 -name '[A-Za-z]*[A-Za-z0-9]' \
1144 -type f
-size +39c
-size -1001c -exec awk '
1146 function process(fn, fnt, hashes, hcnt, fl, hi) {
1147 fnt = fn; sub(/^.*\//, "", fnt)
1148 if (length(fnt) > 31 || fnt !~ /^[A-Za-z][A-Za-z0-9_-]*[A-Za-z0-9]$/) return;
1150 while (getline fl < fn) {
1151 sub(/\t.*$/, "", fl)
1152 if (length(fl) < 40 || fl !~ /^[0-9a-fA-F][0-9a-fA-F]*$/) {hcnt = 0; break;}
1153 hashes[++hcnt] = fl;
1156 for (hi=1;hi<=hcnt;++hi) print tolower(hashes[hi]);
1158 END {for (idx=1;idx<ARGC;++idx) process(ARGV[idx])}
1159 ' '{}' '+' 2>/dev
/null ||
:
1163 # get_worktrees_friends
1164 # single argument is a (possibly relative) path to a "worktrees" subdir
1165 # if omitted it defaults to "worktrees"
1166 # any "friends" found in there are output to stdout
1167 get_worktrees_friends
() {
1168 if [ -d "${1:-worktrees}" ]; then
1169 find -L "${1:-worktrees}" -mindepth 2 -maxdepth 2 -name HEAD
-type f
-print |
1170 while read -r _lwth
; do
1171 get_detached_head
"$_lwth"
1172 get_detached_friends
"${_lwth%HEAD}"
1173 get_index_tree
"${_lwth%HEAD}index"
1178 # compute_extra_reachables
1179 # create lines suitable for a packed-refs file mentioning all the
1180 # other refs we might like to keep.
1181 # the current directory MUST be set to the repository's --git-dir
1182 # the following are included:
1183 # * refs mentioned in repack/packed-refs.extra (if it exists)
1184 # * refs mentioned in reflogs/... files
1185 # * tree(s) created from index file(s)
1186 # * detached linked working tree heads
1187 # Resulting objects are tested for existence and uniqified then output
1188 # one per line under a refs/z* namespace
1189 compute_extra_reachables
() {
1191 if [ -s repack
/packed-refs.extra
]; then
1192 LC_ALL
=C
sed <repack
/packed-refs.extra
-n \
1193 -e 's/^\([0-9A-Fa-f][0-9A-Fa-f]*\).*$/\1/p' \
1194 -e 's/^\^\([0-9A-Fa-f][0-9A-Fa-f]*\).*$/\1/p'
1196 digits8
='[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
1197 find -L reflogs
-mindepth 1 -maxdepth 1 -type f
-name "$digits8*" -exec gzip -c -d -f '{}' + |
1198 LC_ALL
=C
awk '{print $2; print $3}'
1199 get_detached_friends .
1200 ! [ -f index
] || get_index_tree index
1201 get_worktrees_friends
1203 is_git_dir private
&&
1204 [ "$(cd objects && pwd -P)" = "$(cd private/objects && pwd -P)" ] &&
1205 [ "$(cd refs && pwd -P)" != "$(cd private/refs && pwd -P)" ]
1207 git
--git-dir=private show-ref
--head --hash 2>/dev
/null ||
:
1208 get_detached_friends private
1209 ! [ -f private
/index
] || get_index_tree private
/index
1210 get_worktrees_friends private
/worktrees
1212 } | LC_ALL
=C
sort -u |
1213 git cat-file
${var_have_git_260:+--buffer} --batch-check"${var_have_git_185:+=%(objectname)}" |
1214 LC_ALL
=C
awk '!/missing/ {num++; print $1 " " "refs/" substr("zzzzzzzzzzzz", 1, length(num)) "/" num}'
1221 # Everything else is more efficient if we do this first
1222 # The "--prune" option is the default since v1.5.0 but it serves as "documentation" here
1223 git pack-refs
--all --prune
1224 [ -e packed-refs
] ||
>>packed-refs
# should never happen...
1226 # If we have a logs directory or a worktrees directory expire the ref logs now
1227 # Note that Git itself does not use either --rewrite or --updateref, so neither do we
1228 ! [ -d logs
] && ! [ -d worktrees
] ||
eval git reflog expire
--all "${quiet:+>/dev/null 2>&1}" ||
:
1231 ! [ -e .gc_failed
] ||
exit 1
1232 rm -f .gc_in_progress
# make sure
1233 touch .gc_in_progress
# it's truly fresh
1234 rm -f bundles
/* objects
/pack
/pack-
*.bndl
1235 # These only exist for a brief time before the packs loose their _f suffix
1236 # "Push Pack Redux" does not apply to these since they were only ever present with _f
1237 rm -f objects
/pack
/pack-
*_f.keep
1238 # This is perhaps a bit aggressive in that if we're suffering from "Push Pack Redux"
1239 # and somehow we get run again immediately after the run where "Push Pack Redux" happened
1240 # and we have garbage collection forced, there's just the barest, almost negligible,
1241 # possibility that the "Push Pack Redux" ref updates _still_ have not happened and we
1242 # should not be removing _r .keep files. None of the normal Girocco processing can
1243 # cause this. The second run of this script would have to use the force gc option
1244 # for it to even be possible in the first place. What's much more likely is that
1245 # the initial run of this script was somehow interrupted in the middle before it
1246 # could get rid of the _r .keep file itself in which case it's better to get rid of
1247 # it now to avoid keeping something around that would perturb our nice and neat gc
1248 rm -f objects
/pack
/pack-
*_r.keep
1249 # We will add .keep files for _u and _l packs if and when we run phase III
1250 # Otherwise they need to not have any .keep files during phases I and II
1251 rm -f objects
/pack
/pack-
*_
[ul
].keep
1253 # We need to make sure that any non-Girocco (barely tolerated) Git object creation
1254 # activity will be able to "freshen" the pack containing a pre-existing object
1255 # that's being written. This really should not be necessary as the pre-receive
1256 # hook should make sure this takes place for any incoming pushes.
1257 # However, do it here anyway just in case.
1258 make_packs_ugw objects
/pack
1260 # This is only effective with Git v2.3.5 and later and it will only matter when
1261 # we are using one of the "internal_rev_list" modes of pack-objects
1262 # (the combine-packs.sh script never uses any of those modes)
1263 # The "git repack" and "git prune" commands always set this internally themselves
1264 # It makes no difference if there's no repository corruption
1265 GIT_REF_PARANOIA
=1 && export GIT_REF_PARANOIA
1267 # All of the options we might want to use with pack-objects were supported
1268 # at some point prior to Git version v1.6.6 which is the minimum version that
1269 # Girocco now requires. Except for one (--use-bitmap-index). Several of them
1270 # are "boiler plate" options we always want to use so we bundle them up here.
1271 pkopt
="--delta-base-offset --keep-true-parents --non-empty --all-progress-implied"
1272 # We want to use --include-tag, but before Git v2.10.1 it would leave out
1273 # "middle" tags (e.g. a tag of a tag of a commit would omit the tagged tag)
1274 # See http://repo.or.cz/git.git/b773ddea2cd3b08c for details
1275 # ("pack-objects: walk tag chains for --include-tag", 2016-09-07, v2.10.1)
1276 # This is not a free check as it matches all refs against refs/tags/ then
1277 # peels all the annotated tags and checks for inclusion. The situation in
1278 # which it would add a tag that was not already included by a reachability
1279 # trace that included tag starting points can only occur if a new tag gets
1280 # pushed during gc pointing to something that would have been packed anyway.
1281 # But, it could happen and, really, compared to gc as a whole it's not that
1282 # expensive to perform (provided we do not get an unconnected pack).
1283 [ -z "$var_have_git_2101" ] || pkopt
="$pkopt --include-tag"
1284 pkopt
="$pkopt ${quiet:---progress} $packopts"
1286 # The git pack-objects command only supports bitmaps if all objects are being
1287 # packed (the "--all" option) and the "--stdout" option is NOT being used.
1288 # Additionally, while packing, if any encountered reachable objects are
1289 # determined to be "not wanted" then no bitmap index will be written anyway.
1290 # While it is theoretically possible that a project with a non-empty alternates
1291 # file ends up packing all objects (because it does not actually use any of the
1292 # objects found in the alternates), it's very unlikely. And, in the unlikely
1293 # event that did occur, clients would see a message about only using one bitmap
1294 # because Git can only use one bitmap at a time and at least one of the
1295 # alternates is bound to have a bitmap. Therefore if we see a non-empty
1296 # alternates file, we disable writing bitmaps which avoids the warning and any
1297 # possibility of a client warning as well. Also if we are running anything
1298 # before Git v2.1.0 (the effective version for repack.writeBitmaps=true) then
1299 # we also always disable bitmap writing.
1301 [ -z "$var_have_git_210" ] || wbmopt
="--write-bitmap-index"
1302 # More recent versions of pack-objects have optimizations when not using the
1303 # --local option. If we do not have any alternates it's a pointless option.
1304 # If we do have alternates we need to skip writing a bitmap and we cannot
1305 # have a bundle since it must contain all objects.
1306 if [ -n "$isfork" ]; then
1320 [ -n "$wbmopt" ] || wbmstr
=" (bitmaps disabled)"
1321 progress
"~ [$proj] running primary full gc pack-objects$wbmstr ($(date))"
1324 ! has_forks_with_alternates
"$proj" || gotforks
=1
1326 # To avoid "Push Pack Redux" (see docs/technical/gc.txt), after collecting the
1327 # initial preexisting non-keep pack list, we rename them so that an incoming push
1328 # pack cannot possibly experience a pack name collision. Git does not require
1329 # use of the "default" pack names, simply that the proper extensions are used.
1330 # We rename to insert an "_r" just before the extension to avoid "Push Pack Redux"
1331 # name collisions. Later on we may create an "unreachable" pack for hard-linking
1332 # down into forks and it will have an "_u" inserted just before its extension.
1333 packlist
="$(list_packs -C objects/pack --all --exclude-no-idx --exclude-keep --quiet .)" ||
:
1335 for oldpack
in $packlist; do
1336 oldpack
="${oldpack%.pack}"
1337 [ -f "objects/pack/$oldpack.pack" ] ||
{
1338 echo >&2 "[$proj] unable to list old pack files"
1341 case "$oldpack" in pre-auto-gc-
[12])
1342 # we never disturb pre-auto-gc-1 or pre-auto-gc-2 packs
1345 oldpackhex
="${oldpack#pack-}"
1346 if [ "${oldpackhex#*[!0-9a-fA-F]}" != "$oldpackhex" ]; then
1347 # names not exclusively hexadecimal do not need renaming
1350 # _l packs are treated like still-unpacked loose objects
1353 # _f packs can only be left over from a previously interrupted gc;
1354 # they need to be renamed to _r now so they're not confused with
1355 # any freshly generated "final" packs (and we already removed
1356 # any pre-existing *_f.keep files so we're good to go)
1359 oldpacks
="${oldpacks:+$oldpacks }$oldpack"
1363 rename_pack
"objects/pack/$oldpack" "objects/pack/${oldpack%_f}_r" ||
{
1364 echo >&2 "[$proj] unable to rename old pack files"
1367 # If the oldpack has a .keep now it means a "Push Pack Redux" is actually
1368 # in progress at this moment and we need to .keep the renamed pack,
1369 # otherwise no "Push Pack Redux" has started yet or it has already finished.
1370 # In either case we're okay because if it's just finished then all ref
1371 # changes have already been made so we don't need a .keep and we will
1372 # see the ref changes and grab all the objects via a reachability trace.
1373 # If it hasn't started yet that's okay because we're done moving that
1374 # name so a complete pack will appear under the old name that we'll
1376 if [ -f "objects/pack/$oldpack.keep" ]; then
1377 echo "Push Pack Redux" >"objects/pack/${oldpack%_f}_r.keep"
1379 oldpacks
="${oldpacks:+$oldpacks }${oldpack%_f}_r"
1383 # We wish to keep deltas from our last full pack so if we're not redeltaing
1384 # then make sure the .pack associated with the .bitmap has a newer mod time
1385 # (If there is no .bitmap then touch the pack with the most objects instead.)
1386 if [ -z "$newdeltas" ]; then
1387 bmpack
="$(list_packs --exclude-no-bitmap --exclude-no-idx --max-matches 1 objects/pack)"
1388 [ -n "$bmpack" ] || bmpack
="$(list_packs --exclude-no-idx --max-matches 1 --object-limit -1 --include-boundary objects/pack)"
1389 if [ -n "$bmpack" ] && [ -f "$bmpack" ] && [ -s "$bmpack" ]; then
1391 touch -c "$bmpack" 2>/dev
/null ||
:
1392 # We must touch .gc_in_progress here to avoid $bmpack looking
1393 # like it's been "freshened" when redundant packs are removed
1394 # It's okay if they have the same mod time, but POSIX does not
1395 # guarantee an ordering for the "touching" that occurs which is
1396 # why this must be a separate command but needs no "sleep 1"
1397 touch .gc_in_progress
1401 # Now we need to make sure that any "freshening" that takes place will actually
1402 # result in a "newer" modification time than the .gc_in_progress file now has
1405 # We run git pack-objects from the repack subdirectory so we can force
1406 # optimized packs to be generated even for repositories that do not have any
1408 packs
="$(git --git-dir=repack pack-objects </dev/null \
1409 $pkopt --all $newdeltas $lclopt ${wbmopt:---honor-pack-keep} "$@
" repack/alt/pack/pack)"
1411 [ $packcnt -eq 1 ] || makebndl
=
1417 progress
"~ [$proj] running supplementary gc pack-objects ($(date))"
1419 # Add the "supplementary" refs
1420 compute_extra_reachables
>>repack
/packed-refs
1422 # Subtract the primary refs
1423 GIT_ALTERNATE_OBJECT_DIRECTORIES
="$PWD/repack/alt"
1424 export GIT_ALTERNATE_OBJECT_DIRECTORIES
1426 # For this one we MUST use --local and MUST NOT use --write-bitmap-index
1427 # However, if there is a "logs" subdirectory we need to use --reflog
1428 # We do add it, just in case, if the linked working trees dir is present
1429 # We do not add --indexed-objects as that requires v2.2.0 and it's unclear
1430 # if it properly includes linked working tree index files or not. The
1431 # above compute_extra_reachables has already included all index trees (thereby
1432 # providing proper --indexed-objects support for all Git versions) making the
1433 # option completely unnecessary.
1435 ! [ -d logs
] && ! [ -d worktrees
] || rflopt
=--reflog
1436 spacks
="$(git --git-dir=repack pack-objects </dev/null \
1437 $pkopt --honor-pack-keep --all $rflopt $newdeltas --local "$@
" repack/alt/pack/pack)"
1443 # There's nothing to do for Phase III unless we have forks that refer to our
1444 # project from their alternates file
1447 if [ -n "$gotforks" ]; then
1449 progress
"~ [$proj] running keep-unreachable gc pack-objects for forks ($(date))"
1451 # If we are a fork, any pre-existing _u packs need to have a .keep
1452 # for this phase and be added to the hlpacks list otherwise (we are
1453 # not a fork) pre-existing _u packs are anomalies to be treated like
1454 # regular non-_u packs
1455 if [ -n "$isfork" ]; then
1456 for upack
in $
(find -L objects
/pack
-mindepth 1 -maxdepth 1 -name "pack-$octet20*_[ul].pack" -print); do
1457 upack
="${upack%.pack}"
1458 [ -e "$upack.keep" ] ||
echo "unreachable" >"$upack.keep"
1459 case "$upack" in *_l
);;*)
1460 hlpacks
="${hlpacks:+$hlpacks }${upack#objects/pack/pack-}"
1464 # Using either --no-reuse-delta or --no-reuse-object together with the
1465 # --keep-unreachable option is a very, very, very bad idea when good
1466 # packs are the desired outcome. If newdeltas are being generated
1467 # then we pack to a temp name, and use combine-packs.sh to get a better
1468 # pack as the result to avoid making a bad --keep-unreachable pack
1470 [ -z "$newdeltas" ] || pfx
="ku"
1471 upacks
="$(git --git-dir=repack pack-objects </dev/null \
1472 $pkopt --honor-pack-keep --all $rflopt --keep-unreachable --local "$@
" repack/alt/pack/${pfx}pack)"
1473 if [ -n "$upacks" ] && [ -n "$newdeltas" ]; then
1474 progress
"~ [$proj] rebuilding keep-unreachable pack deltas"
1477 printf "repack
/alt
/pack
/${pfx}pack-
%s.pack
\n" $oldupacks |
1478 run_combine_packs --names --weak-naming --non-empty --all-progress-implied ${quiet:---progress} \
1479 $packopts $newdeltas "$@
" repack/alt/pack/pack)"
1480 eval rm -f "$(printf \""repack
/alt
/pack
/${pfx}pack-
%s.
*"\"" " $oldupacks)"
1482 for upack
in $upacks; do
1483 rename_pack
"repack/alt/pack/pack-$upack" "repack/alt/pack/pack-${upack}_u"
1485 rm -f objects
/pack
/pack-
*_
[ul
].keep
1486 [ -z "$hlpacks" ] && [ -z "$upacks" ] ||
1487 progress
"~ [$proj] hard-linking keep-unreachable pack(s) into immediate child forks"
1489 # We have to update the lastparentgc time in the child forks even if they do not get any
1490 # new "unreachable packs" because they need to run gc just in case the parent now has some
1491 # objects that used to only be in the child so they can be removed from the child.
1492 # For example, a "patch" might be developed first in a fork and then later accepted into
1493 # the parent in which case the objects making up the patch in the child fork are now
1494 # redundant (since they're now in the parent as well) and need to be removed from the
1495 # child fork which can only happen if the child fork runs gc.
1496 lastparentgc
="$(date "$datefmt")"
1498 # It is enough to copy objects just one level down and get_repo_list
1499 # takes a regular expression (which is automatically prefixed with '^')
1500 # so we can easily match forks exactly one level down from this project
1502 get_repo_list
"$forkdir/[^/:][^/:]*:" |
1504 # Ignore forks that do not exist or are symbolic links
1505 ! [ -L "$cfg_reporoot/$fork.git" ] && [ -d "$cfg_reporoot/$fork.git" ] ||
1507 # Or have an empty alternates file
1508 ! is_empty_alternates_file
"$cfg_reporoot/$fork.git/objects/info/alternates" ||
1511 # Match hlpacks in parent project if any
1512 if [ -n "$hlpacks" ]; then
1513 mkdir
-p "$cfg_reporoot/$fork.git/objects/pack"
1514 eval ln -f "$(printf '"objects
/pack
/pack-
%s.pack
" ' $hlpacks)" \
1515 "$(printf '"objects
/pack
/pack-
%s.idx
" ' $hlpacks)" \
1516 '"$cfg_reporoot/$fork.git/objects/pack/"'
1519 # Match upacks in repack/alt area if any
1520 if [ -n "$upacks" ]; then
1521 mkdir
-p "$cfg_reporoot/$fork.git/objects/pack"
1522 eval ln -f "$(printf '"repack
/alt
/pack
/pack-
%s_u.pack
" ' $upacks)" \
1523 "$(printf '"repack
/alt
/pack
/pack-
%s_u.idx
" ' $upacks)" \
1524 '"$cfg_reporoot/$fork.git/objects/pack/"'
1527 if ! [ -e "$cfg_reporoot/$fork.git/.needsgc" ]; then
1528 # Trigger a mini gc in the fork if it now has too many packs
1529 packs
="$(list_packs --quiet --count --exclude-no-idx --exclude-keep "$cfg_reporoot/$fork.git
/objects
/pack
")" ||
:
1530 if [ -n "$packs" ] && [ "$packs" -ge 20 ]; then
1531 >"$cfg_reporoot/$fork.git/.needsgc"
1534 [ -z "$runupdate" ] || git
--git-dir="$cfg_reporoot/$fork.git" update-server-info
1535 # Update the fork's lastparentgc date (must be more recent than $gcstart)
1536 git
--git-dir="$cfg_reporoot/$fork.git" config gitweb.lastparentgc
"$lastparentgc"
1540 # Now move any primary/supplementary packs back into objects/pack
1541 # then drop any "unfreshened" redundant packs and clear repack/alt
1543 # First make sure the primary pack(s) have the most recent mod time
1544 if [ -n "$packs" ]; then
1545 [ -z "$spacks" ] ||
sleep 1
1546 printf 'repack/alt/pack/pack-%s.pack\n' $packs |
xargs touch -c 2>/dev
/null ||
:
1549 # Move the packs into place but with a _f suffix and a .keep file for now
1550 for pack
in $packs $spacks; do
1551 rename_pack
"repack/alt/pack/pack-$pack" "objects/pack/pack-${pack}_f"
1552 [ -e "objects/pack/pack-${pack}_f.keep" ] ||
1553 echo "final" >"objects/pack/pack-${pack}_f.keep"
1556 # It's possible that one of the $oldpacks had a .bitmap, got renamed (along
1557 # with its .bitmap) and then got "freshened" causing us to not remove it
1558 # However, if $wbmopt is set we most likely now have TWO .bitmap packs!
1559 # This can produce ugly warnings we don't want and possibly get the wrong
1560 # bitmap used since only one .bitmap file can ever be used by Git.
1561 # If this has happened, the .bitmap we want to discard will always have
1562 # an _r suffix so we can just zap any such now since it will leave the pack.
1563 [ -z "$wbmopt" ] ||
rm -f objects
/pack
/pack-
*_r.bitmap ||
:
1565 # Remove the redundant packs that have not since been "freshened"
1566 # This does not completely eliminate the race condition window (Girocco's own
1567 # activites -- gc/fetch/receive are immune to the race) but it substantially
1568 # shrinks it down to just the time after the find but before the following rm
1570 [ -z "$oldpacks" ] ||
1571 printf 'objects/pack/%s.pack\n' $oldpacks |
1572 LC_ALL
=C
sort >repack
/oldpacks
1573 find -L objects
/pack
-maxdepth 1 -type f
-name "pack-$octet20*.pack" -newer .gc_in_progress
-print |
1574 LC_ALL
=C
sort >repack
/freshened
1575 deadpacks
="$(LC_ALL=C join -v 1 repack/oldpacks repack/freshened | LC_ALL=C sed 's/\.pack$//')"
1576 [ -z "$deadpacks" ] ||
1577 eval echo "$(printf '"%s
".* ' $deadpacks)" |
xargs rm -f ||
:
1579 # No need for this anymore
1580 rm -rf repack
/alt objects
/pack
/repack
1581 unset GIT_ALTERNATE_OBJECT_DIRECTORIES
1587 progress
"~ [$proj] running gc prune-packed"
1589 # We do not want the redundant packs or any new "--keep-unreachable" pack(s) to be
1590 # present while running prune-packed. We try to guarantee that any loose object
1591 # (or any object present in a pack with an _l suffix which was created by mini gc)
1592 # that's unreachable persists for at least one $Girocco::Config::min_gc_interval
1593 # (not withstanding administrator interference to force earlier gc to occur).
1594 # If we were to include the redundant/keep-unreachable pack(s) when running
1595 # prune-packed and a loose unreachable object happened to be duplicated in one
1596 # of them we would end up removing it too soon and void our guarantee.
1597 git prune-packed
$quiet
1599 progress
"~ [$proj] running loose objects gc pack-objects ($(date))"
1601 # Although Git v2.10.0 and later support a --pack-loose-unreachable option,
1602 # we MUST NOT use it for these reasons:
1603 # 1) We're not interested in expensive "unreachable" at this point, only "loose"
1604 # 2) It produces simply horrid packs about 3.8x times larger than they should be
1605 # 3) We don't require anything more than Git v1.6.6
1606 # The only way we could see any _o pack files at this point is if one got
1607 # "freshened" while we were running gc. If that happens then it gets to live on
1608 # until the next full gc and we need to include it in the loose repack here.
1609 lpacks
="$(list_packs --exclude-no-idx --exclude-no-sfx _l --exclude-no-sfx _o --quiet objects/pack |
1610 run_combine_packs --replace --names --loose --weak-naming --non-empty --honor-pack-keep \
1611 --all-progress-implied ${quiet:---progress} $packopts $newdeltas "$@
")"
1613 if [ -n "$lpacks" ]; then
1614 # Make sure any primary pack(s) have a more recent mod time than "unreachable" objects packs
1615 if [ -n "$packs" ]; then
1617 printf 'objects/pack/pack-%s_f.pack\n' $packs |
xargs touch -c 2>/dev
/null ||
:
1619 # We need to identify these packs later so we don't combine_packs them
1620 for objpack
in $lpacks; do
1621 rename_pack
"objects/pack/pack-$objpack" "objects/pack/pack-${objpack}_o" ||
:
1625 # Polish up the final packs now
1626 rm -f objects
/pack
/pack-
*_f.keep
1627 for pack
in $packs $spacks; do
1628 rename_pack
"objects/pack/pack-${pack}_f" "objects/pack/pack-$pack"
1631 if [ -n "$lpacks" ]; then
1632 # Finally zap the corresponding loose objects
1633 progress
"~ [$proj] running packed loose objects gc prune-packed"
1634 git prune-packed
$quiet
1637 ! [ -e .gc_failed
] ||
exit 1
1638 # These, if they exist, are now meaningless and need to be removed
1639 rm -f gfi-packs .needsgc .needspack .needspackgc
1641 # Make sure this stays up to date
1642 git update-server-info
1644 # We must make loose objects group writable so that they
1645 # can be freshened by other pushers. Technically we need only do this for
1646 # push projects but to enable mirror projects to be more easily converted to
1647 # push projects, we go ahead and do it for all projects.
1648 # By the time we get here we really shouldn't have any of these, but just in case.
1649 { find -L objects
/$octet -type f
-name "$octet19*" -exec chmod ug
+w
'{}' + ||
:; } 2>/dev
/null
1651 # darcs mirrors have a xxx.log file that will grow endlessly
1652 # if this is a mirror and the file exists, shorten it to 10000 lines
1653 # also take this opportunity to optimize the darcs repo
1654 if ! [ -e .nofetch
] && [ -n "$cfg_mirror" ]; then
1655 url
="$(config_get baseurl)" ||
:
1656 case "$url" in darcs
://* | darcs
+http
://* | darcs
+https
://*)
1657 if [ -n "$cfg_mirror_darcs" ]; then
1659 basedarcs
="$(basename "${url#darcs*:/}")"
1660 if [ -f "$basedarcs.log" ]; then
1661 tail -n 10000 "$basedarcs.log" >"$basedarcs.log.$$"
1662 mv -f "$basedarcs.log.$$" "$basedarcs.log"
1664 if [ -d "$basedarcs.darcs" ]; then
1666 cd "$basedarcs.darcs"
1667 # without show_progress suppress non-error output
1668 [ "${show_progress:-0}" != "0" ] ||
exec >/dev
/null
1669 # Note that this does not optimize _darcs/inventories/ :(
1677 # Create a matching .bndl header file for the all-in-one pack we just created
1678 # but only if we're not a fork (otherwise the bundle would not be complete)
1679 # and we are running at least Git version 1.7.2 (pack_is_complete always fails otherwise)
1680 if [ -n "$makebndl" ] && [ -n "$var_have_git_172" ]; then
1681 # There should only be one pack in $packs but do some checking...
1682 # The one we just created will have a .idx and will NOT have a .keep
1683 progress
"~ [$proj] creating downloadable bundle header"
1686 IFS
= read -r curhead
<repack
/HEAD.orig ||
:
1688 [ -s "objects/pack/pack-$packs.pack" ] &&
1689 [ -s "objects/pack/pack-$packs.idx" ] &&
1690 ! [ -e "objects/pack/pack-$packs.keep" ] &&
1691 pkhead
="$(pack_is_complete "$PWD/objects
/pack
/pack-
$packs.pack
" \
1692 "$PWD/repack
/packed-refs.orig
" "$curhead")"
1694 pkbase
="objects/pack/pack-$packs"
1696 if [ -n "$pkbase" ] && [ -n "$pkhead" ]; then
1699 case "$curhead" in "ref: refs/"?
*|
"ref:refs/"?
*|
"refs/"?
*)
1700 symref
="${curhead#ref:}"
1701 symref
="${symref# }"
1704 [ -z "$cfg_httpbundleurl" ] || bndlurl
=" url=$cfg_httpbundleurl/$proj.git/clone.bundle"
1705 echo "# v2 git bundle"
1706 LC_ALL
=C
sed -ne "/^$octet20$hexdig* refs\/[^ $tab]*\$/ p" <repack
/packed-refs.orig
1707 if [ -n "$symref" ]; then
1708 printf "$pkhead HEAD\0symref=HEAD:%s%s\n" "$symref" "$bndlurl"
1710 if [ -n "$bndlurl" ]; then
1711 printf "$pkhead HEAD\0%s\n" "${bndlurl# }"
1718 bndletag
="$("$cfg_basedir/bin
/rangecgi
" --etag -m 1 "$pkbase.bndl
" "$pkbase.pack
")" ||
:
1719 bndlsha
="$(printf '%s' "$bndletag" | git hash-object --stdin)" ||
:
1720 if [ -n "$bndletag" ]; then
1721 case "$bndlsha" in $octet20*)
1722 bndlshatrailer
="${bndlsha#????????}"
1723 bndlshaprefix
="${bndlsha%$bndlshatrailer}"
1724 bndlname
="$(TZ=UTC date +%Y%m%d_%H%M%S)-${bndlshaprefix:-0}"
1725 [ -d bundles
] || mkdir bundles
1726 echo "${pkbase#objects/pack/}.bndl" >"bundles/$bndlname"
1727 echo "${pkbase#objects/pack/}.pack" >>"bundles/$bndlname"
1728 ln -s -f -n "$bndlname" bundles
/latest
1734 # Record the size of this repo as the sum of its clone packed-refs + *.pack sizes as 1024-byte blocks
1735 eval "reposizek=$(( $(
1736 echo 0 $(du -k repack/packed-refs.orig $(printf 'objects/pack/pack-%s.pack ' $packs) 2>/dev/null |
1737 LC_ALL=C awk '{print $1}') |
1738 LC_ALL=C sed -e 's/ / + /g') ))"
1739 config_set_raw girocco.reposizek
"${reposizek:-0}"
1741 # Now we're finally done with this
1744 # We didn't used to do anything about rerere or worktrees but we're
1745 # trying to make nice with linked working trees these days :)
1746 # Maybe even non-bare repositories too, but *shush* about those ;)
1747 if [ -n "$var_have_git_250" ] && [ -d worktrees
]; then
1748 # The value "3.months.ago" is hard-coded into gc.c rather than
1749 # having the default be in worktree.c so we must provide it if
1750 # we get nothing out of the gc.worktreePruneExpire config item
1751 # Prior to Git v2.6.0 the config item was gc.pruneworktreesexpire
1752 # however we just always use the newer name no matter what Git version
1753 expiry
="$(git config --get gc.worktreePruneExpire 2>/dev/null)" ||
:
1754 eval git worktree prune
--expire '"${expiry:-3.months.ago}"' "${quiet:+>/dev/null 2>&1}" ||
:
1756 # git rerere does it right and handles its own default/config'd expiration values
1757 ! [ -d rr-cache
] ||
eval git rerere gc
"${quiet:+>/dev/null 2>&1}" ||
:
1759 # We use $gcstart here to avoid a race where a push occurs during the gc itself
1760 # and the next future gc could be incorrectly skipped if we used the current
1761 # timestamp here instead
1762 config_set lastgc
"$gcstart"
1765 progress
"- [$proj] garbage check ($(date))"