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 --delta-base-offset \
50 --non-empty --threads=1 $quiet objects
/pack
/packtmp | \
51 while read -r _newpack
; do
52 rm -f objects
/pack
/pack-
$_newpack.
*
53 ln objects
/pack
/packtmp-
$_newpack.pack objects
/pack
/pack-
$_newpack.pack
54 ln objects
/pack
/packtmp-
$_newpack.idx objects
/pack
/pack-
$_newpack.idx
55 rm -f objects
/pack
/packtmp-
$_newpack.
*
61 cd "$cfg_reporoot/$proj.git"
63 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
64 datefmt
='+%a, %d %b %Y %T %z'
66 if check_interval lastgc
$cfg_min_gc_interval; then
67 progress
"= [$proj] garbage check skip (last at $(config_get lastgc))"
71 progress
"x [$proj] garbage check disabled"
75 # Avoid unnecessary garbage collections:
76 # 1. If lastreceive is set and is older than lastgc
78 # 2. We are not a fork (! -s alternates) -OR- lastparentgc is older than lastgc
80 # If lastgc is NOT set or lastreceive is NOT set we MUST run gc
81 # If we are a fork and lastparentgc is NOT set we MUST run gc
83 gcstart
="$(date "$datefmt")"
86 [ -s objects
/info
/alternates
] && isfork
=1
88 [ -n "$isfork" ] && lastparentgcsecs
="$(config_get_date_seconds lastparentgc || :)"
90 if lastreceivesecs
="$(config_get_date_seconds lastreceive)" && \
91 lastgcsecs
="$(config_get_date_seconds lastgc)" && \
92 [ $lastreceivesecs -lt $lastgcsecs ]; then
93 # We've run gc since we last received, so maybe we can skip,
94 # check if not fork or fork and lastparentgc < lastgc
95 if [ -n "$isfork" ]; then
96 if [ -n "$lastparentgcsecs" ] && \
97 [ $lastparentgcsecs -lt $lastgcsecs ]; then
98 # We've run gc since our parent ran gc so we can skip
102 # We don't have any alternates (we're not a forK) so we can skip
107 # be compatibile with gc.pid file from newer Git releases
112 if [ "$(createlock "$lockf")" ]; then
114 # 1) less than 12 hours old
115 # 2) contains two fields (pid hostname) NO trailing NL
116 # 3) the hostname is different OR the pid is still alive
117 # then we exit as another active process is holding the lock
118 if [ "$(find "$lockf" -mmin -720 -print 2>/dev/null)" ]; then
121 read -r apid ahost ajunk
< "$lockf" ||
:
122 if [ "$apid" ] && [ "$ahost" ]; then
123 if [ "$ahost" != "$hn" ] || pidactive
"$apid"; then
129 echo >&2 "[$proj] unable to create gc.pid.lock file"
132 if [ -n "$active" ]; then
134 echo >&2 "[$proj] gc already running on machine '$ahost' pid '$apid'"
137 printf "%s %s" "$$" "$hn" > "$lockf.lock"
138 chmod 0664 "$lockf.lock"
139 mv -f "$lockf.lock" "$lockf"
141 if [ -n "$skipgc" ]; then
142 progress
"= [$proj] garbage check nothing to do (`date`)"
143 config_set lastgc
"$gcstart"
149 if [ -n "$isfork" ] && [ -z "$lastparentgcsecs" ]; then
150 # set lastparentgc and then update gcstart to be at least 1 second later
151 config_set lastparentgc
"$gcstart"
154 if [ -z "$lastreceivesecs" ]; then
155 # set lastreceive and then update gcstart to be at least 1 second later
156 config_set lastreceive
"$gcstart"
159 if [ -n "$bumptime" ]; then
161 gcstart
="$(date "$datefmt")"
164 progress
"+ [$proj] garbage check (`date`)"
166 # safe pruning: we put all our objects in all forks, then we can
167 # safely get rid of extra ones; repacks in forks will get rid of
168 # the redundant ones again then
170 if [ -d "../${forkdir##*/}" ]; then
171 # It is enough to copy objects just one level down and get_repo_list
172 # takes a regular expression (which is automatically prefixed with '^')
173 # so we can easily match forks exactly one level down from this project
174 get_repo_list
"$forkdir/[^/]*:" |
176 # Ignore forks that do not exist or are symbolic links
177 [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \
179 # Or do not have a non-zero length alternates file
180 [ -s "$cfg_reporoot/$fork.git/objects/info/alternates" ] || \
182 # Match objects in parent project
183 for d
in objects
/?? objects
/pack
; do
184 [ "$d" != "objects/??" ] ||
continue
185 mkdir
-p "$cfg_reporoot/$fork.git/$d"
186 [ "$d" != "objects/pack" ] || \
187 [ "$(echo objects/pack/*)" != \
188 "objects/pack/*" ] || \
190 ln -f "$d"/* "$cfg_reporoot/$fork.git/$d" ||
:
192 # Update the fork's lastparentgc date (must be current, not $gcstart)
193 GIT_DIR
="$cfg_reporoot/$fork.git" git config \
194 gitweb.lastparentgc
"$(date "$datefmt")"
198 quiet
=; [ -n "$show_progress" ] || quiet
=-q
201 git repack
$packopts -a -d -l $quiet
203 git update-server-info
204 # darcs:// mirrors have a xxx.log file that will grow endlessly
205 # if this is a mirror and the file exists, shorten it to 10000 lines
206 # also take this opportunity to optimize the darcs repo
207 if [ ! -e .nofetch
] && [ -n "$cfg_mirror" ]; then
208 url
="$(config_get baseurl || :)"
209 case "$url" in darcs
://*)
210 if [ -n "$cfg_mirror_darcs" ]; then
212 basedarcs
="$(basename "${url#darcs:/}")"
213 if [ -f "$basedarcs.log" ]; then
214 tail -n 10000 "$basedarcs.log" > "$basedarcs.log.$$"
215 mv -f "$basedarcs.log.$$" "$basedarcs.log"
217 if [ -d "$basedarcs.darcs" ]; then
219 cd "$basedarcs.darcs"
220 # Note that this does not optimize _darcs/inventories/ :(
227 # We use $gcstart here to avoid a race where a push occurs during the gc itself
228 # and the next future gc could be incorrectly skipped if we used the current
229 # timestamp here instead
230 config_set lastgc
"$gcstart"
233 progress
"- [$proj] garbage check (`date`)"