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 # be compatibile with gc.pid file from newer Git releases
80 if [ "$(createlock "$lockf")" ]; then
82 # 1) less than 12 hours old
83 # 2) contains two fields (pid hostname) NO trailing NL
84 # 3) the hostname is different OR the pid is still alive
85 # then we exit as another active process is holding the lock
86 if [ "$(find "$lockf" -mmin -720 -print 2>/dev/null)" ]; then
89 read -r apid ahost ajunk
< "$lockf" ||
:
90 if [ "$apid" ] && [ "$ahost" ]; then
91 if [ "$ahost" != "$hn" ] || pidactive
"$apid"; then
97 echo >&2 "[$proj] unable to create gc.pid.lock file"
100 if [ -n "$active" ]; then
102 echo >&2 "[$proj] gc already running on machine '$ahost' pid '$apid'"
105 printf "%s %s" "$$" "$hn" > "$lockf.lock"
106 chmod 0664 "$lockf.lock"
107 mv -f "$lockf.lock" "$lockf"
109 progress
"+ [$proj] garbage check (`date`)"
111 # safe pruning: we put all our objects in all forks, then we can
112 # safely get rid of extra ones; repacks in forks will get rid of
113 # the redundant ones again then
115 if [ -d "../${forkdir##*/}" ]; then
116 # It is enough to copy objects just one level down and get_repo_list
117 # takes a regular expression (which is automatically prefixed with '^')
118 # so we can easily match forks exactly one level down from this project
119 get_repo_list
"$forkdir/[^/]*:" |
121 # Ignore forks that do not exist or are symbolic links
122 [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \
124 # Match objects in parent project
125 for d
in objects
/?? objects
/pack
; do
126 [ "$d" != "objects/??" ] ||
continue
127 mkdir
-p "$cfg_reporoot/$fork.git/$d"
128 [ "$d" != "objects/pack" ] || \
129 [ "$(echo objects/pack/*)" != \
130 "objects/pack/*" ] || \
132 ln -f "$d"/* "$cfg_reporoot/$fork.git/$d" ||
:
134 # Update the fork's lastparentgc date
135 GIT_DIR
="$cfg_reporoot/$fork.git" git config \
136 gitweb.lastparentgc
"$(date '+%a, %d %b %Y %T %z')"
140 quiet
=; [ -n "$show_progress" ] || quiet
=-q
143 git repack
$packopts -a -d -l $quiet
145 git update-server-info
146 # darcs:// mirrors have a xxx.log file that will grow endlessly
147 # if this is a mirror and the file exists, shorten it to 10000 lines
148 # also take this opportunity to optimize the darcs repo
149 if [ ! -e .nofetch
] && [ -n "$cfg_mirror" ]; then
150 url
="$(config_get baseurl || :)"
151 case "$url" in darcs
://*)
152 if [ -n "$cfg_mirror_darcs" ]; then
154 basedarcs
="$(basename "${url#darcs:/}")"
155 if [ -f "$basedarcs.log" ]; then
156 tail -n 10000 "$basedarcs.log" > "$basedarcs.log.$$"
157 mv -f "$basedarcs.log.$$" "$basedarcs.log"
159 if [ -d "$basedarcs.darcs" ]; then
161 cd "$basedarcs.darcs"
162 # Note that this does not optimize _darcs/inventories/ :(
169 config_set lastgc
"$(date "$datefmt")"
172 progress
"- [$proj] garbage check (`date`)"