]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - git-hooks/zephyr-post-receive
zephyr-post-receive: Abort after 10 zephyrs to prevent zwrite flood
[Scripts/git/.git] / git-hooks / zephyr-post-receive
CommitLineData
efdbeff7 1#!/bin/bash
5b11b497
GT
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
10class=`git config zephyr.class`
916beed8 11instance=`git config zephyr.instance`
5b11b497 12zsig=`git config zephyr.zsig`
aa39c04d
NE
13color=`git config --bool zephyr.color`
14
15if [ "${color:-true}" = "true" ]; then
16 usecolor="--color"
17else
18 usecolor=""
19fi
20
b0d563fe
GT
21if [ -z "$zsig" ]; then
22 if [ -e "$GIT_DIR/description" ]; then
23 zsig=`cat "$GIT_DIR/description"`
24 fi
fe93b4bc
EB
25 if [ -z "$zsig" ] || \
26 [ "$zsig" = "Unnamed repository; edit this file to name it for gitweb." ] || \
27 [ "$zsig" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
efdbeff7 28 zsig=$(basename "$(cd "$GIT_DIR" && pwd)")
b0d563fe 29 if [ "$zsig" = ".git" ]; then
efdbeff7 30 zsig=$(basename "$(cd "$GIT_DIR/.." && pwd)")
b0d563fe
GT
31 fi
32 fi
33fi
34
5b11b497
GT
35if [ -z "$class" ]; then
36 echo "I don't know where to send a commit zephyr!" >&2
37 echo "Please set the zephyr.class config variable in" >&2
38 echo "$PWD/config." >&2
39 exit 1
40fi
72b08995
AK
41
42let max=10
43check_max () {
44 if ! let --max; then
45 zwrite -c "$class" -i "${instance:-git}" -s "Aperture Science Emergency Intelligence Incinerator" -d \
46 -m 'Aborting zephyr hook to prevent zwrite flood.'
47 exit 0
48 fi
49}
50
5b11b497 51while read oldrev newrev refname; do
d0ef17b3 52 if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
72b08995 53 check_max
d0ef17b3 54 # dammit git
a4574a07 55 zwrite -c "$class" -i "${instance:-${refname#refs/heads/}}" -s "$zsig: $refname" -d \
210a5c8a 56 -m "New branch $refname created, currently at $newrev."
d0ef17b3
GT
57 continue
58 fi
72b08995
AK
59 while read rev; do
60 check_max
5b11b497 61 shortrev=`git log -1 --pretty=format:%h "$rev"`
7f3e83eb 62 (git show --stat -M $usecolor "$rev" |
5dceef3e
AK
63 sed -e 's/@/@@/g' \
64 -e 's/}/@(})/g' \
65 -e 's/\e\[m/}@{/g' \
66 -e 's/\e\[33m/@color(yellow)/g' \
67 -e 's/\e\[31m/@color(red)/g' \
68 -e 's/\e\[32m/@color(green)/g' \
69 -e '1s/^/@{/' \
70 -e '$s/$/}/') |
b0d563fe 71 zwrite -c "$class" -i "${instance:-$shortrev}" -s "$zsig: $refname" -d
72b08995 72 done < <(git rev-list --first-parent --reverse "$oldrev..$newrev")
5b11b497 73done