clone.sh: unset gitweb.lastgc on success
[girocco.git] / jobd / gc.sh
blob920004d2da46fc326dc12571d3ca10fee4cfea2f
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 set -e
6 trap 'if [ $? != 0 ]; then echo "gc failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
8 umask 002
9 [ "$cfg_permission_control" != "Hooks" ] || umask 000
11 proj="$1"
12 cd "$cfg_reporoot/$proj.git"
14 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
15 datefmt='+%a, %d %b %Y %T %z'
17 if check_interval lastgc $cfg_min_gc_interval; then
18 progress "= [$proj] garbage check skip (last at $(config_get lastgc))"
19 exit 0
21 if [ -e .nogc ]; then
22 progress "x [$proj] garbage check disabled"
23 exit 0
25 progress "+ [$proj] garbage check (`date`)"
27 # safe pruning: we put all our objects in all forks, then we can
28 # safely get rid of extra ones; repacks in forks will get rid of
29 # the redundant ones again then
30 forkdir="$1"
31 if [ -d "../${forkdir##*/}" ]; then
32 # It is enough to copy objects just one level down and get_repo_list
33 # takes a regular expression (which is automatically prefixed with '^')
34 # so we can easily match forks exactly one level down from this project
35 get_repo_list "$forkdir/[^/]*:" |
36 while read fork; do
37 # Ignore forks that do not exist or are symbolic links
38 [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \
39 continue
40 # Match objects in parent project
41 for d in objects/?? objects/pack; do
42 [ "$d" != "objects/??" ] || continue
43 mkdir -p "$cfg_reporoot/$fork.git/$d"
44 [ "$d" != "objects/pack" ] || \
45 [ "$(echo objects/pack/*)" != \
46 "objects/pack/*" ] || \
47 continue
48 ln -f "$d"/* "$cfg_reporoot/$fork.git/$d" || :
49 done
50 done
53 quiet=; [ -n "$show_progress" ] || quiet=-q
54 git repack -a -d --window=50 --window-memory=1G --depth=50 -l $quiet
55 git prune
56 git update-server-info
57 config_set lastgc "$(date "$datefmt")"
59 progress "- [$proj] garbage check (`date`)"