@matheusbsbs / matheus-bagliano / commits / b03e7b7d76
Fork 0

post-receive-email: optional message line count limit

We have become used to the features of svnmailer when used with Subversion, and one of those useful features is that it can limit the maximum length (in lines) of a commit email message. This is terribly useful since once the goes beyond a reasonable number of lines, nobody is going to read the remainder, and if they really want the entire contents of the commits, they can use git itself to get them using the revision IDs present in the message already. Change the post-receive-email script to respond to an 'emailmaxlines' config key which, if specified, will limit the number of lines generated (including headers); any lines beyond the limit are suppressed, and a final line is added indicating the number that were suppressed. Signed-off-by: Kevin P. Fleming <kpfleming@digium.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin P. Fleming committed Jul 16, 2010 at 14:16 UTC b03e7b7d76e79de14e76df5d4e2ee727f4522a95
1 file changed +32 -2
contrib/hooks/post-receive-email
+32 -2
@@ -55,6 +55,11 @@
55 # "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo"
56 # Be careful if "..." contains things that will be expanded by shell "eval"
57 # or printf.
58 +# hooks.emailmaxlines
59 +# The maximum number of lines that should be included in the generated
60 +# email body. If not specified, there is no limit.
61 +# Lines beyond the limit are suppressed and counted, and a final
62 +# line is added indicating the number of suppressed lines.
63 #
64 # Notes
65 # -----
@@ -84,6 +89,7 @@ generate_email()
89 oldrev=$(git rev-parse $1)
90 newrev=$(git rev-parse $2)
91 refname="$3"
92 + maxlines=$4
93
94 # --- Interpret
95 # 0000->1234 (create)
@@ -192,7 +198,12 @@ generate_email()
198 fn_name=atag
199 ;;
200 esac
195 - generate_${change_type}_${fn_name}_email
201 +
202 + if [ -z "$maxlines" ]; then
203 + generate_${change_type}_${fn_name}_email
204 + else
205 + generate_${change_type}_${fn_name}_email | limit_lines $maxlines
206 + fi
207
208 generate_email_footer
209 }
@@ -642,6 +653,24 @@ show_new_revisions()
653 }
654
655
656 +limit_lines()
657 +{
658 + lines=0
659 + skipped=0
660 + while IFS="" read -r line; do
661 + lines=$((lines + 1))
662 + if [ $lines -gt $1 ]; then
663 + skipped=$((skipped + 1))
664 + else
665 + printf "%s\n" "$line"
666 + fi
667 + done
668 + if [ $skipped -ne 0 ]; then
669 + echo "... $skipped lines suppressed ..."
670 + fi
671 +}
672 +
673 +
674 send_mail()
675 {
676 if [ -n "$envelopesender" ]; then
@@ -679,6 +708,7 @@ announcerecipients=$(git config hooks.announcelist)
708 envelopesender=$(git config hooks.envelopesender)
709 emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
710 custom_showrev=$(git config hooks.showrev)
711 +maxlines=$(git config hooks.emailmaxlines)
712
713 # --- Main loop
714 # Allow dual mode: run from the command line just like the update hook, or
@@ -691,6 +721,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
721 else
722 while read oldrev newrev refname
723 do
694 - generate_email $oldrev $newrev $refname | send_mail
724 + generate_email $oldrev $newrev $refname $maxlines | send_mail
725 done
726 fi