From: Alex Dehnert Date: Tue, 26 Mar 2013 03:58:01 +0000 (-0400) Subject: Resync zephyr-post-receive with upstream X-Git-Tag: 0.1.25_glasgall1~4 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dev.git/commitdiff_plain/e18b24c5a3314a430c66eae6f2c47e52ba1ab66f Resync zephyr-post-receive with upstream This incorporates the changes in snippets from 7f3e83eb49926fd6bf2d60ee2a9642640e5b8b0b ("zephyr-post-receive: Detect renames." by Anders) to 0a6422ec6a30429215c4a93dd5a40799712c09b0 ("zephyr-post-receive: fix quoting and tabs" by me). --- diff --git a/git-hooks/sub/zephyr-post-receive b/git-hooks/sub/zephyr-post-receive index 3cb2086..293cae6 100755 --- a/git-hooks/sub/zephyr-post-receive +++ b/git-hooks/sub/zephyr-post-receive @@ -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 @@ -13,6 +13,7 @@ class=$(invirt-getconf "$base.class" 2>/dev/null) instance=$(invirt-getconf "$base.instance" 2>/dev/null) zsig=$(invirt-getconf "$base.zsig" 2>/dev/null) color=$(invirt-getconf "$base.color" 2>/dev/null) +maxlines=`git config --int zephyr.maxlines 2>/dev/null || echo 50` # Git hooks are always called with PWD == GIT_DIR. repo=${PWD#/srv/git/} @@ -24,30 +25,64 @@ else 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 provide a value for $base.class in" >&2 echo "your invirt config file." >&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 "$repo" -s "${zsig:-Git}: $refname" -d \ - -m "New branch ${refname#refs/heads/} created." + -m "New branch ${refname#refs/heads/} 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" | + 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/\[m/}@{/g' \ + -e 's/\[1m/}@b{/g' \ -e 's/\[33m/@color(yellow)/g' \ -e 's/\[31m/@color(red)/g' \ -e 's/\[32m/@color(green)/g' \ + -e 's/\[36m/@color(cyan)/g' \ -e '1s/^/@{/' \ -e '$s/$/}/') | zwrite -c "$class" -i "${instance:-$repo/$shortrev}" -s "${zsig:-Git}: $refname" -d - done + done < <(git rev-list --first-parent --reverse "$oldrev..$newrev") done