]> sipb.mit.edu Git - snippets/.git/blob - git-hooks/zephyr-post-receive
zephyr-post-receive: fix quoting and tabs
[snippets/.git] / git-hooks / zephyr-post-receive
1 #!/bin/bash
2 #
3 # This script is run after receive-pack has accepted a pack and the
4 # repository has been updated.  It is passed arguments in through stdin
5 # in the form
6 #  <oldrev> <newrev> <refname>
7 # For example:
8 #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
9
10 class=`git config zephyr.class`
11 instance=`git config zephyr.instance`
12 zsig=`git config zephyr.zsig`
13 color=`git config --bool zephyr.color`
14 maxlines=`git config --int zephyr.maxlines 2>/dev/null || echo 50`
15
16 if [ "${color:-true}" = "true" ]; then
17     usecolor="--color"
18 else
19     usecolor=""
20 fi
21
22 if [ -z "$zsig" ]; then
23     if [ -e "$GIT_DIR/description" ]; then
24         zsig=`cat "$GIT_DIR/description"`
25     fi
26     if [ -z "$zsig" ] || \
27         [ "$zsig" = "Unnamed repository; edit this file to name it for gitweb." ] || \
28         [ "$zsig" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
29         zsig=$(basename "$(cd "$GIT_DIR" && pwd)")
30         if [ "$zsig" = ".git" ]; then
31             zsig=$(basename "$(cd "$GIT_DIR/.." && pwd)")
32         fi
33     fi
34 fi
35
36 if [ -z "$class" ]; then
37   echo "I don't know where to send a commit zephyr!" >&2
38   echo "Please set the zephyr.class config variable in" >&2
39   echo "$PWD/config." >&2
40   exit 1
41 fi
42
43 let max=10
44 check_max () {
45   if ! let --max; then
46     zwrite -c "$class" -i "${instance:-git}" -s "Aperture Science Emergency Intelligence Incinerator" -d \
47       -m 'Aborting zephyr hook to prevent zwrite flood.'
48     exit 0
49   fi
50 }
51
52 while read oldrev newrev refname; do
53   if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
54     check_max
55     # dammit git
56     zwrite -c "$class" -i "${instance:-${refname#refs/heads/}}" -s "$zsig: $refname" -d \
57       -m "New branch $refname created, currently at $newrev."
58     continue
59   fi
60   while read rev; do
61     check_max
62     shortrev=`git log -1 --pretty=format:%h "$rev"`
63     lines=`git show -M "$rev" | wc -l`
64     if [ $lines -lt $maxlines ]; then
65         stat=""
66     else
67         stat="--stat"
68     fi
69     (git show -M $stat $usecolor "$rev" |
70      sed -e 's/@/@@/g' \
71          -e 's/}/@(})/g' \
72          -e 's/\e\[m/}@{/g' \
73          -e 's/\e\[1m/}@b{/g' \
74          -e 's/\e\[33m/@color(yellow)/g' \
75          -e 's/\e\[31m/@color(red)/g' \
76          -e 's/\e\[32m/@color(green)/g' \
77          -e 's/\e\[36m/@color(cyan)/g' \
78          -e '1s/^/@{/' \
79          -e '$s/$/}/') |
80     zwrite -c "$class" -i "${instance:-$shortrev}" -s "$zsig: $refname" -d
81   done < <(git rev-list --first-parent --reverse "$oldrev..$newrev")
82 done