6 trap 'if [ $? != 0 ]; then echo "gc failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
9 packopts
='--window=50 --window-memory=1g --depth=50'
12 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
15 if _result
="$(kill -0 "$1" 2>&1)"; then
16 # process exists and we have permission to signal it
19 case "$_result" in *"not permitted"*)
20 # we do not have permission to signal the process
23 # process does not exist
29 if (set -C; > "$1.lock") 2>/dev
/null
; then
34 [ "$_try" != "p" ] ||
sleep 1
36 # cannot create temp file
40 # if the current directory is_gfi_mirror then repack all packs listed in gfi-packs
42 is_gfi_mirror ||
return 0
43 [ -s gfi-packs
] ||
return 0
44 while IFS
=': ' read -r _pack _junk
; do
45 if [ -s "$_pack" -a -s "${_pack%.pack}.idx" ]; then
46 git show-index
< "${_pack%.pack}.idx" | cut
-d ' ' -f 2
49 git pack-objects
$packopts --no-reuse-delta --threads=1 $quiet objects
/pack
/packtmp | \
50 while read -r _newpack
; do
51 rm -f objects
/pack
/pack-
$_newpack.
*
52 ln objects
/pack
/packtmp-
$_newpack.pack objects
/pack
/pack-
$_newpack.pack
53 ln objects
/pack
/packtmp-
$_newpack.idx objects
/pack
/pack-
$_newpack.idx
54 rm -f objects
/pack
/packtmp-
$_newpack.
*
60 cd "$cfg_reporoot/$proj.git"
62 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
63 datefmt
='+%a, %d %b %Y %T %z'
65 if check_interval lastgc
$cfg_min_gc_interval; then
66 progress
"= [$proj] garbage check skip (last at $(config_get lastgc))"
70 progress
"x [$proj] garbage check disabled"
74 # be compatibile with gc.pid file from newer Git releases
79 if [ "$(createlock "$lockf")" ]; then
81 # 1) less than 12 hours old
82 # 2) contains two fields (pid hostname) NO trailing NL
83 # 3) the hostname is different OR the pid is still alive
84 # then we exit as another active process is holding the lock
85 if [ "$(find "$lockf" -mmin -720 -print 2>/dev/null)" ]; then
88 read -r apid ahost ajunk
< "$lockf" ||
:
89 if [ "$apid" ] && [ "$ahost" ]; then
90 if [ "$ahost" != "$hn" ] || pidactive
"$apid"; then
96 echo >&2 "[$proj] unable to create gc.pid.lock file"
99 if [ -n "$active" ]; then
101 echo >&2 "[$proj] gc already running on machine '$ahost' pid '$apid'"
104 printf "%s %s" "$$" "$hn" > "$lockf.lock"
105 chmod 0664 "$lockf.lock"
106 mv -f "$lockf.lock" "$lockf"
108 progress
"+ [$proj] garbage check (`date`)"
110 # safe pruning: we put all our objects in all forks, then we can
111 # safely get rid of extra ones; repacks in forks will get rid of
112 # the redundant ones again then
114 if [ -d "../${forkdir##*/}" ]; then
115 # It is enough to copy objects just one level down and get_repo_list
116 # takes a regular expression (which is automatically prefixed with '^')
117 # so we can easily match forks exactly one level down from this project
118 get_repo_list
"$forkdir/[^/]*:" |
120 # Ignore forks that do not exist or are symbolic links
121 [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \
123 # Match objects in parent project
124 for d
in objects
/?? objects
/pack
; do
125 [ "$d" != "objects/??" ] ||
continue
126 mkdir
-p "$cfg_reporoot/$fork.git/$d"
127 [ "$d" != "objects/pack" ] || \
128 [ "$(echo objects/pack/*)" != \
129 "objects/pack/*" ] || \
131 ln -f "$d"/* "$cfg_reporoot/$fork.git/$d" ||
:
136 quiet
=; [ -n "$show_progress" ] || quiet
=-q
139 git repack
$packopts -a -d -l $quiet
141 git update-server-info
142 # darcs:// mirrors have a xxx.log file that will grow endlessly
143 # if this is a mirror and the file exists, shorten it to 10000 lines
144 # also take this opportunity to optimize the darcs repo
145 if [ ! -e .nofetch
] && [ -n "$cfg_mirror" ]; then
146 url
="$(config_get baseurl || :)"
147 case "$url" in darcs
://*)
148 if [ -n "$cfg_mirror_darcs" ]; then
150 basedarcs
="$(basename "${url#darcs:/}")"
151 if [ -f "$basedarcs.log" ]; then
152 tail -n 10000 "$basedarcs.log" > "$basedarcs.log.$$"
153 mv -f "$basedarcs.log.$$" "$basedarcs.log"
155 if [ -d "$basedarcs.darcs" ]; then
157 cd "$basedarcs.darcs"
158 # Note that this does not optimize _darcs/inventories/ :(
165 config_set lastgc
"$(date "$datefmt")"
168 progress
"- [$proj] garbage check (`date`)"