6 trap 'if [ $? != 0 ]; then echo "gc failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
9 [ "$cfg_permission_control" != "Hooks" ] ||
umask 000
12 if _result
="$(kill -0 "$1" 2>&1)"; then
13 # process exists and we have permission to signal it
16 case "$_result" in *"not permitted"*)
17 # we do not have permission to signal the process
20 # process does not exist
26 if (set -o noclobber
; > "$1.lock") 2>/dev
/null
; then
31 [ "$_try" != "p" ] ||
sleep 1
33 # cannot create temp file
38 cd "$cfg_reporoot/$proj.git"
40 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
41 datefmt
='+%a, %d %b %Y %T %z'
43 if check_interval lastgc
$cfg_min_gc_interval; then
44 progress
"= [$proj] garbage check skip (last at $(config_get lastgc))"
48 progress
"x [$proj] garbage check disabled"
52 # be compatibile with gc.pid file from newer Git releases
57 if [ "$(createlock "$lockf")" ]; then
59 # 1) less than 12 hours old
60 # 2) contains two fields (pid hostname) NO trailing NL
61 # 3) the hostname is different OR the pid is still alive
62 # then we exit as another active process is holding the lock
63 if [ "$(find "$lockf" -mmin -720 -print 2>/dev/null)" ]; then
66 read -r apid ahost ajunk
< "$lockf" ||
:
67 if [ "$apid" ] && [ "$ahost" ]; then
68 if [ "$ahost" != "$hn" ] || pidactive
"$apid"; then
74 echo >&2 "[$proj] unable to create gc.pid.lock file"
77 if [ -n "$active" ]; then
79 echo >&2 "[$proj] gc already running on machine '$ahost' pid '$apid'"
82 printf "%s %s" "$$" "$hn" > "$lockf.lock"
83 chmod 0664 "$lockf.lock"
84 mv -f "$lockf.lock" "$lockf"
86 progress
"+ [$proj] garbage check (`date`)"
88 # safe pruning: we put all our objects in all forks, then we can
89 # safely get rid of extra ones; repacks in forks will get rid of
90 # the redundant ones again then
92 if [ -d "../${forkdir##*/}" ]; then
93 # It is enough to copy objects just one level down and get_repo_list
94 # takes a regular expression (which is automatically prefixed with '^')
95 # so we can easily match forks exactly one level down from this project
96 get_repo_list
"$forkdir/[^/]*:" |
98 # Ignore forks that do not exist or are symbolic links
99 [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \
101 # Match objects in parent project
102 for d
in objects
/?? objects
/pack
; do
103 [ "$d" != "objects/??" ] ||
continue
104 mkdir
-p "$cfg_reporoot/$fork.git/$d"
105 [ "$d" != "objects/pack" ] || \
106 [ "$(echo objects/pack/*)" != \
107 "objects/pack/*" ] || \
109 ln -f "$d"/* "$cfg_reporoot/$fork.git/$d" ||
:
114 quiet
=; [ -n "$show_progress" ] || quiet
=-q
116 git repack
-a -d --window=50 --window-memory=1G
--depth=50 -l $quiet
118 git update-server-info
119 config_set lastgc
"$(date "$datefmt")"
122 progress
"- [$proj] garbage check (`date`)"