gc.sh: small optimization when dealing with forks
[girocco.git] / jobd / gc.sh
blobb74eb0eb495138992367edcf745eaa890fda2f07
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 proj="$1"
9 cd "$cfg_reporoot/$proj.git"
11 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
12 datefmt='+%a, %d %b %Y %T %z'
14 if check_interval lastgc $cfg_min_gc_interval; then
15 progress "= [$proj] garbage check skip (last at $(config_get lastgc))"
16 exit 0
18 if [ -e .nogc ]; then
19 progress "x [$proj] garbage check disabled"
20 exit 0
22 progress "+ [$proj] garbage check (`date`)"
24 # safe pruning: we put all our objects in all forks, then we can
25 # safely get rid of extra ones; repacks in forks will get rid of
26 # the redundant ones again then
27 forkdir="$1"
28 if [ -d "../${forkdir##*/}" ]; then
29 # It is enough to copy objects just one level down and get_repo_list
30 # takes a regular expression (which is automatically prefixed with '^')
31 # so we can easily match forks exactly one level down from this project
32 get_repo_list "$forkdir/[^/]*:" |
33 while read fork; do
34 # Ignore forks that do not exist or are symbolic links
35 [ ! -L "$cfg_reporoot/$fork.git" -a -d "$cfg_reporoot/$fork.git" ] || \
36 continue
37 # Match objects in parent project
38 for d in objects/?? objects/pack; do
39 [ "$d" != "objects/??" ] || continue
40 mkdir -p "$cfg_reporoot/$fork.git/$d"
41 [ "$d" != "objects/pack" ] || \
42 [ "$(echo objects/pack/*)" != \
43 "objects/pack/*" ] || \
44 continue
45 ln -f "$d"/* "$cfg_reporoot/$fork.git/$d" || :
46 done
47 done
50 quiet=; [ -n "$show_progress" ] || quiet=-q
51 git repack -a -d --window-memory=1G -l $quiet
52 git prune
53 git update-server-info
54 config_set lastgc "$(date "$datefmt")"
56 progress "- [$proj] garbage check (`date`)"