aboutsummaryrefslogtreecommitdiff
path: root/update-server-info-fallback.sh
blob: a8ff3e26212c41483bc2e25479617011fe61829f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
#
# This script runs "git update-server-info" on repositories which
# didn't have it run in some time. This script is intended to be
# run as cronjob, and serve as backup means to do "git update-server-info"
# in case git/gerrit hook based update fail/misbehave.
#

GITROOT=/srv/repositories
# Max age since git update-server-info was run in minutes, use leading "+" for "more than"
MAXAGE="+60"
# find experssion for dirs to exclude
EXCLUDE="-path '*/lost+found' -prune -o"
# Process so many repos per invocation
CHUNK=500


if [ $(id -u -n) = "root" ]; then
    echo "This script must not be run as 'root' user"
    exit 1
fi

# GNU find up to 4.4.2 has a bug, that if it is started with unreadable
# current directory, it will fail with:
# find: pred.c:1932: launch: Assertion `starting_desc >= 0' failed.
# So, set dir to a safe one.
cd /tmp

# Resolve symlinks, as find won't work with a symlink unless it has trailing /.
GITROOT=$(readlink -e $GITROOT)

find_stale_info_refs () {
    find $GITROOT -path '*/lost+found' -prune -o \
        -path '*.git/info' -type d '!' -exec test -e "{}/refs" ';' \
        -print | sed 's|/info$||'


    # First find expression ignores lost+found dir
    find $GITROOT -path '*/lost+found' -prune -o \
        -path '*.git/info/refs' -mmin "$MAXAGE" -print \
        | sed -e 's|/info/refs||'
}

for dir in $(find_stale_info_refs | uniq | head -n $CHUNK); do
#    (echo $dir; ls -l $dir/info/refs) >>/tmp/update-server-info-fallback.log
    (cd $dir; git update-server-info || echo "Error while processing $dir")
    # Workaround for issue with git 2.2.1: http://article.gmane.org/gmane.comp.version-control.git/262026
    chmod +r $dir/info/refs $dir/objects/info/packs
#    (ls -l $dir/info/refs $dir/objects/info/packs; echo) >>/tmp/update-server-info-fallback.log
done