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