]> sipb.mit.edu Git - snippets/.git/blobdiff - git-hooks/zephyr-post-receive
zephyr-post-receive: Set UTF-8 locale
[snippets/.git] / git-hooks / zephyr-post-receive
index 19260d7bd1de7afe682699fc35ebcfaa2618ba37..595234c22b9ed3e69bcca6081851fa33a7d1ad4e 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # This script is run after receive-pack has accepted a pack and the
 # repository has been updated.  It is passed arguments in through stdin
 #
 # This script is run after receive-pack has accepted a pack and the
 # repository has been updated.  It is passed arguments in through stdin
@@ -7,10 +7,13 @@
 # For example:
 #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
 
 # For example:
 #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
 
+export LC_ALL=en_US.UTF-8
+
 class=`git config zephyr.class`
 instance=`git config zephyr.instance`
 zsig=`git config zephyr.zsig`
 color=`git config --bool zephyr.color`
 class=`git config zephyr.class`
 instance=`git config zephyr.instance`
 zsig=`git config zephyr.zsig`
 color=`git config --bool zephyr.color`
+maxlines=`git config --int zephyr.maxlines 2>/dev/null || echo 50`
 
 if [ "${color:-true}" = "true" ]; then
     usecolor="--color"
 
 if [ "${color:-true}" = "true" ]; then
     usecolor="--color"
@@ -18,21 +21,64 @@ else
     usecolor=""
 fi
 
     usecolor=""
 fi
 
+if [ -z "$zsig" ]; then
+    if [ -e "$GIT_DIR/description" ]; then
+        zsig=`cat "$GIT_DIR/description"`
+    fi
+    if [ -z "$zsig" ] || \
+        [ "$zsig" = "Unnamed repository; edit this file to name it for gitweb." ] || \
+        [ "$zsig" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
+        zsig=$(basename "$(cd "$GIT_DIR" && pwd)")
+        if [ "$zsig" = ".git" ]; then
+            zsig=$(basename "$(cd "$GIT_DIR/.." && pwd)")
+        fi
+    fi
+fi
+
 if [ -z "$class" ]; then
   echo "I don't know where to send a commit zephyr!" >&2
   echo "Please set the zephyr.class config variable in" >&2
   echo "$PWD/config." >&2
   exit 1
 fi
 if [ -z "$class" ]; then
   echo "I don't know where to send a commit zephyr!" >&2
   echo "Please set the zephyr.class config variable in" >&2
   echo "$PWD/config." >&2
   exit 1
 fi
+
+let max=10
+check_max () {
+  if ! let --max; then
+    zwrite -c "$class" -i "${instance:-git}" -s "Aperture Science Emergency Intelligence Incinerator" -d \
+      -m 'Aborting zephyr hook to prevent zwrite flood.'
+    exit 0
+  fi
+}
+
 while read oldrev newrev refname; do
 while read oldrev newrev refname; do
-  git-rev-list --reverse "$oldrev..$newrev" | while read rev; do
+  if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
+    check_max
+    # dammit git
+    zwrite -c "$class" -i "${instance:-${refname#refs/heads/}}" -s "$zsig: $refname" -d \
+      -m "New branch $refname created, currently at $newrev."
+    continue
+  fi
+  while read rev; do
+    check_max
     shortrev=`git log -1 --pretty=format:%h "$rev"`
     shortrev=`git log -1 --pretty=format:%h "$rev"`
-    (git show --stat $usecolor "$rev" |
-     sed "s/@/@@/g" |
-     sed "s/\e\[m/@color(default)/g" |
-     sed "s/\e\[33m/@color(yellow)/g" |
-     sed "s/\e\[31m/@color(red)/g" |
-     sed "s/\e\[32m/@color(green)/g") |
-    zwrite -c "$class" -i "${instance:-$shortrev}" -s "${zsig:-Git}: $refname" -d
-  done
+    lines=`git show -M "$rev" | wc -l`
+    if [ $lines -lt $maxlines ]; then
+        stat=""
+    else
+        stat="--stat"
+    fi
+    (git show -M $stat $usecolor "$rev" |
+     sed -e 's/@/@@/g' \
+         -e 's/}/@(})/g' \
+         -e 's/\e\[m/}@{/g' \
+         -e 's/\e\[1m/}@b{/g' \
+         -e 's/\e\[33m/@color(yellow)/g' \
+         -e 's/\e\[31m/@color(red)/g' \
+         -e 's/\e\[32m/@color(green)/g' \
+         -e 's/\e\[36m/@color(cyan)/g' \
+         -e '1s/^/@{/' \
+         -e '$s/$/}/') |
+    zwrite -c "$class" -i "${instance:-$shortrev}" -s "$zsig: $refname" -d
+  done < <(git rev-list --first-parent --reverse "$oldrev..$newrev")
 done
 done