Skip to content

Commit b03e7b7

Browse files
Kevin P. Fleminggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53b3042 commit b03e7b7

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

contrib/hooks/post-receive-email

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
# "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo"
5656
# Be careful if "..." contains things that will be expanded by shell "eval"
5757
# 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.
5863
#
5964
# Notes
6065
# -----
@@ -84,6 +89,7 @@ generate_email()
8489
oldrev=$(git rev-parse $1)
8590
newrev=$(git rev-parse $2)
8691
refname="$3"
92+
maxlines=$4
8793

8894
# --- Interpret
8995
# 0000->1234 (create)
@@ -192,7 +198,12 @@ generate_email()
192198
fn_name=atag
193199
;;
194200
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
196207

197208
generate_email_footer
198209
}
@@ -642,6 +653,24 @@ show_new_revisions()
642653
}
643654

644655

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+
645674
send_mail()
646675
{
647676
if [ -n "$envelopesender" ]; then
@@ -679,6 +708,7 @@ announcerecipients=$(git config hooks.announcelist)
679708
envelopesender=$(git config hooks.envelopesender)
680709
emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
681710
custom_showrev=$(git config hooks.showrev)
711+
maxlines=$(git config hooks.emailmaxlines)
682712

683713
# --- Main loop
684714
# 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
691721
else
692722
while read oldrev newrev refname
693723
do
694-
generate_email $oldrev $newrev $refname | send_mail
724+
generate_email $oldrev $newrev $refname $maxlines | send_mail
695725
done
696726
fi

0 commit comments

Comments
 (0)