]> sipb.mit.edu Git - snippets/.git/blobdiff - git-hooks/zephyr-post-receive
zephyr-post-receive: Abort after 10 zephyrs to prevent zwrite flood
[snippets/.git] / git-hooks / zephyr-post-receive
index a929432b3aef5c03b56a211b791aad24de3a37c1..51b9660fe95b4029d026ba4e954f1d2840a42f63 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
@@ -22,10 +22,12 @@ 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." ]; then
-        zsig=$(basename "$(readlink -f "$GIT_DIR")")
+    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 "$(readlink -f "$GIT_DIR/..")")
+            zsig=$(basename "$(cd "$GIT_DIR/.." && pwd)")
         fi
     fi
 fi
@@ -36,14 +38,26 @@ if [ -z "$class" ]; then
   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
   if [ "$oldrev" = "0000000000000000000000000000000000000000" ]; then
+    check_max
     # dammit git
-    zwrite -c "$class" -i "${instance:-$(basename "$refname")}" -s "$zsig: $refname" -d \
+    zwrite -c "$class" -i "${instance:-${refname#refs/heads/}}" -s "$zsig: $refname" -d \
       -m "New branch $refname created, currently at $newrev."
     continue
   fi
-  git rev-list --first-parent --reverse "$oldrev..$newrev" | while read rev; do
+  while read rev; do
+    check_max
     shortrev=`git log -1 --pretty=format:%h "$rev"`
     (git show --stat -M $usecolor "$rev" |
      sed -e 's/@/@@/g' \
@@ -55,5 +69,5 @@ while read oldrev newrev refname; do
          -e '1s/^/@{/' \
          -e '$s/$/}/') |
     zwrite -c "$class" -i "${instance:-$shortrev}" -s "$zsig: $refname" -d
-  done
+  done < <(git rev-list --first-parent --reverse "$oldrev..$newrev")
 done