git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kevin P. Fleming" <kpfleming@digium.com>
To: git@vger.kernel.org
Cc: "Kevin P. Fleming" <kpfleming@digium.com>
Subject: [PATCH] post-receive-email: optional message line count limit
Date: Thu, 15 Jul 2010 09:51:56 -0500	[thread overview]
Message-ID: <1279205516-3302-1-git-send-email-kpfleming@digium.com> (raw)
In-Reply-To: <m2vd8jhxbd.fsf@igel.home>

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.
---
 contrib/hooks/post-receive-email |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 30ae63d..4dc85c2 100755
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -55,6 +55,11 @@
 #     "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo"
 #   Be careful if "..." contains things that will be expanded by shell "eval"
 #   or printf.
+# hooks.emailmaxlines
+#   The maximum number of lines that should be included in the generated
+#   email (including its headers). If not specified, there is no limit.
+#   Lines beyond the limit are suppressed and counted, and a final
+#   line is added indicating the number of suppressed lines.
 #
 # Notes
 # -----
@@ -642,6 +647,27 @@ show_new_revisions()
 }
 
 
+limit_lines()
+{
+	lines=0
+	skipped=0
+	while IFS="" read -r line
+	do
+		lines=$((lines + 1))
+		if [ $lines -gt $1 ]
+		then
+			skipped=$((skipped + 1))
+		else
+			printf "%s\n" "$line"
+		fi
+	done
+	if [ $skipped -ne 0 ]
+	then
+		echo "... $skipped lines suppressed ..."
+	fi
+}
+
+
 send_mail()
 {
 	if [ -n "$envelopesender" ]; then
@@ -679,6 +705,7 @@ announcerecipients=$(git config hooks.announcelist)
 envelopesender=$(git config hooks.envelopesender)
 emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
 custom_showrev=$(git config hooks.showrev)
+maxlines=$(git config hooks.emailmaxlines)
 
 # --- Main loop
 # Allow dual mode: run from the command line just like the update hook, or
@@ -691,6 +718,10 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
 else
 	while read oldrev newrev refname
 	do
-		generate_email $oldrev $newrev $refname | send_mail
+		if [ -z "$maxlines" ]; then
+			generate_email $oldrev $newrev $refname | send_mail
+		else
+			generate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail
+		fi
 	done
 fi
-- 
1.7.1.1

  reply	other threads:[~2010-07-15 14:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-08 19:03 [PATCH] Add support for limiting number of lines generated in messages by post-receive-email Kevin P. Fleming
2010-07-12 16:47 ` Marc Branchaud
2010-07-13 20:56   ` Kevin P. Fleming
2010-07-12 17:10 ` Ævar Arnfjörð Bjarmason
2010-07-13 21:18   ` [PATCH] Optional limit for number of lines generated by script Kevin P. Fleming
2010-07-13 21:43     ` Andreas Schwab
2010-07-15 14:51       ` Kevin P. Fleming [this message]
2010-07-15 17:36         ` [PATCH] post-receive-email: optional message line count limit Junio C Hamano
2010-07-16 19:13           ` Kevin P. Fleming
2010-07-16 19:16           ` Kevin P. Fleming
2010-07-14 16:41     ` [PATCH] Optional limit for number of lines generated by script Marc Branchaud

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1279205516-3302-1-git-send-email-kpfleming@digium.com \
    --to=kpfleming@digium.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).