summaryrefslogtreecommitdiffstats
path: root/gitmirror/robot.sh
blob: 0b0b31c82e412a9b9bff65b44d4a2772cf05b74f (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash -xe

#MAILTO='tip commits list <linux-tip-commits@vger.kernel.org>'
MAILTO='nasm-cvs@lists.sourceforge.net'
SENDER='nasmbuild@nasm.us'
MASTER="$HOME/gitmirror/nasm.git"
MIRROR="/pub/git/nasm/nasm.git"

# /usr/sbin needed for sendmail
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:$HOME/bin

topdir="$HOME/gitmirror"

tmpdir="/tmp/$USER/tipmail"
slave="$HOME/gitmirror/nasm-mail.git"
date=$(date -uR)

(
    if [ x"$1" = x"force" ]; then
	flock -x 9
    else
	flock -nx 9 || exit 0
    fi

    cd "$MASTER"
    git fetch -f

    cd "$MIRROR"
    git fetch -f

    cd "$topdir"

    if [ -f kill/kill ]; then
	exit 0
    fi

    mkdir -m 0700 -p $tmpdir

    ( cd "$slave" && "$topdir"/filter-branches.pl origin ) > branches
    (
	while read branch; do
	    GIT_DIR="$MASTER" git rev-parse --verify -q "$branch"'^{}' || true
	done
    ) < branches > branches.heads
    sha1sum branches.heads > branches.id.new

    if [ "$(cat branches.id)" != "$(cat branches.id.new)" ]; then
	cd "$slave"
	git checkout mail-merge
	OLD_HEAD=$(git rev-parse HEAD)
	git fetch -f
	git merge -s ours -m "Mail run on $date" $(sed -e 's:^:refs/remotes/origin/:' < "$topdir"/branches)
	NEW_HEAD=$(git rev-parse HEAD)

	if [ x"$NEW_HEAD" != x"$OLD_HEAD" ]; then
	    git rev-list --reverse --no-merges ^$OLD_HEAD $NEW_HEAD | (
		while read rev; do
		    "$topdir"/robotfmt.pl $rev "$topdir"/branches
		done
	    )
	fi
	cd "$topdir"

	mv -f branches.id.new branches.id
	mv -f branches.heads branches.heads.saved
    fi
) 9< "$0"