]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - git-hooks/zephyr-post-receive
zephyr-post-receive: Set UTF-8 locale
[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
ed5ec5f5
AK
10export LC_ALL=en_US.UTF-8
11
5b11b497 12class=`git config zephyr.class`
916beed8 13instance=`git config zephyr.instance`
5b11b497 14zsig=`git config zephyr.zsig`
aa39c04d 15color=`git config --bool zephyr.color`
64786cec 16maxlines=`git config --int zephyr.maxlines 2>/dev/null || echo 50`
aa39c04d
NE
17
18if [ "${color:-true}" = "true" ]; then
19 usecolor="--color"
20else
21 usecolor=""
22fi
23
b0d563fe
GT
24if [ -z "$zsig" ]; then
25 if [ -e "$GIT_DIR/description" ]; then
26 zsig=`cat "$GIT_DIR/description"`
27 fi
fe93b4bc
EB
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
efdbeff7 31 zsig=$(basename "$(cd "$GIT_DIR" && pwd)")
b0d563fe 32 if [ "$zsig" = ".git" ]; then
efdbeff7 33 zsig=$(basename "$(cd "$GIT_DIR/.." && pwd)")
b0d563fe
GT
34 fi
35 fi
36fi
37
5b11b497
GT
38if [ -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
43fi
72b08995
AK
44
45let max=10
46check_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
5b11b497 54while read oldrev newrev refname; do
d0ef17b3 55 if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
72b08995 56 check_max
d0ef17b3 57 # dammit git
a4574a07 58 zwrite -c "$class" -i "${instance:-${refname#refs/heads/}}" -s "$zsig: $refname" -d \
210a5c8a 59 -m "New branch $refname created, currently at $newrev."
d0ef17b3
GT
60 continue
61 fi
72b08995
AK
62 while read rev; do
63 check_max
5b11b497 64 shortrev=`git log -1 --pretty=format:%h "$rev"`
64786cec 65 lines=`git show -M "$rev" | wc -l`
64786cec 66 if [ $lines -lt $maxlines ]; then
0a6422ec
AD
67 stat=""
68 else
69 stat="--stat"
64786cec 70 fi
0a6422ec 71 (git show -M $stat $usecolor "$rev" |
5dceef3e
AK
72 sed -e 's/@/@@/g' \
73 -e 's/}/@(})/g' \
74 -e 's/\e\[m/}@{/g' \
0a6422ec 75 -e 's/\e\[1m/}@b{/g' \
5dceef3e
AK
76 -e 's/\e\[33m/@color(yellow)/g' \
77 -e 's/\e\[31m/@color(red)/g' \
78 -e 's/\e\[32m/@color(green)/g' \
64786cec 79 -e 's/\e\[36m/@color(cyan)/g' \
5dceef3e
AK
80 -e '1s/^/@{/' \
81 -e '$s/$/}/') |
b0d563fe 82 zwrite -c "$class" -i "${instance:-$shortrev}" -s "$zsig: $refname" -d
72b08995 83 done < <(git rev-list --first-parent --reverse "$oldrev..$newrev")
5b11b497 84done