git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add support for limiting number of lines generated in messages by post-receive-email
@ 2010-07-08 19:03 Kevin P. Fleming
  2010-07-12 16:47 ` Marc Branchaud
  2010-07-12 17:10 ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 11+ messages in thread
From: Kevin P. Fleming @ 2010-07-08 19:03 UTC (permalink / raw)
  To: git; +Cc: Kevin P. Fleming

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.

This patch adds a new parameter to the post-receive-email hook script called
'maxlines', that defaults to 2048 if not specified. The entire message is
filtered through a function that counts the number of lines generated
(including headers), and any lines beyond the limit are suppressed; if any
lines are suppressed, a final line is added indicating the number that
were suppressed.

Signed-off-by: Kevin P. Fleming <kpfleming@digium.com>
---
 contrib/hooks/post-receive-email |   31 ++++++++++++++++++++++++++++++-
 1 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 30ae63d..436c13f 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.maxlines
+#   The maximum number of lines that should be included in the generated
+#   email (including its headers). If not specified, defaults to 2048.
+#   Lines beyond the limit are suppressed and counted, and a final
+#   line is added indicating the number of suppressed lines.
 #
 # Notes
 # -----
@@ -642,6 +647,29 @@ show_new_revisions()
 }
 
 
+limit_lines()
+{
+    lines=0
+    skipped=0
+    limit=$(($1 - 2))
+    while IFS="" read line
+    do
+	lines=$((lines + 1))
+	if [ $lines -gt $limit ]
+	then
+	    skipped=$((skipped + 1))
+	else
+	    echo "$line"
+	fi
+    done
+    if [ $skipped -ne 0 ]
+    then
+	echo
+	echo "... $skipped lines suppressed ..."
+    fi
+}
+
+
 send_mail()
 {
 	if [ -n "$envelopesender" ]; then
@@ -679,6 +707,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.maxlines || echo '2048')
 
 # --- Main loop
 # Allow dual mode: run from the command line just like the update hook, or
@@ -691,6 +720,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
 else
 	while read oldrev newrev refname
 	do
-		generate_email $oldrev $newrev $refname | send_mail
+		generate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail
 	done
 fi
-- 
1.7.1.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] Add support for limiting number of lines generated in messages by post-receive-email
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Marc Branchaud @ 2010-07-12 16:47 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: git

On 10-07-08 03:03 PM, Kevin P. Fleming wrote:
> 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.
> 
> This patch adds a new parameter to the post-receive-email hook script called
> 'maxlines', that defaults to 2048 if not specified. The entire message is
> filtered through a function that counts the number of lines generated
> (including headers), and any lines beyond the limit are suppressed; if any
> lines are suppressed, a final line is added indicating the number that
> were suppressed.

Hi Kevin,

I appreciate the work and the need you're addressing.  Thanks!

I do have a request though, which is to make this match the current
(unlimited) behavior by default instead of imposing an arbitrary (although
seemingly large) limit.

I admit I don't have a strong reason for this, mainly just a desire to not
force features on folks that don't need them.  IMHO the limit is a bit too
hidden and likely to surprise someone at an inopportune time.  Plus what
would someone do if they *want* no limit?

(FYI, we dealt with large-email syndrome by taking the diffs out of the
emails and using a custom format to embed a gitweb URL instead.  Folks who
care about the actual code change can browse the commit in gitweb.  This also
helped make it easier for humans to parse the emails and the commits they
contain.)

A couple more comments below...

> Signed-off-by: Kevin P. Fleming <kpfleming@digium.com>
> ---
>  contrib/hooks/post-receive-email |   31 ++++++++++++++++++++++++++++++-
>  1 files changed, 30 insertions(+), 1 deletions(-)
> 
> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
> index 30ae63d..436c13f 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.maxlines

Why not call this something like "hooks.maxemaillines"?  "maxlines" is so
generic that it might collide with something some other hook might use.

> +#   The maximum number of lines that should be included in the generated
> +#   email (including its headers). If not specified, defaults to 2048.
> +#   Lines beyond the limit are suppressed and counted, and a final
> +#   line is added indicating the number of suppressed lines.
>  #
>  # Notes
>  # -----
> @@ -642,6 +647,29 @@ show_new_revisions()
>  }
>  
>  
> +limit_lines()
> +{
> +    lines=0
> +    skipped=0
> +    limit=$(($1 - 2))
> +    while IFS="" read line
> +    do
> +	lines=$((lines + 1))
> +	if [ $lines -gt $limit ]
> +	then
> +	    skipped=$((skipped + 1))
> +	else
> +	    echo "$line"
> +	fi
> +    done
> +    if [ $skipped -ne 0 ]
> +    then
> +	echo
> +	echo "... $skipped lines suppressed ..."
> +    fi
> +}
> +
> +
>  send_mail()
>  {
>  	if [ -n "$envelopesender" ]; then
> @@ -679,6 +707,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.maxlines || echo '2048')
>  
>  # --- Main loop
>  # Allow dual mode: run from the command line just like the update hook, or
> @@ -691,6 +720,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
>  else
>  	while read oldrev newrev refname
>  	do
> -		generate_email $oldrev $newrev $refname | send_mail
> +		generate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail

I'm a little concerned about the performance hit of piping the output through
limit_lines(), which buffers all the lines in memory.  Folks who want large
emails might get bitten by this.

(That said, I don't know anything about the memory efficiency of the shell's
pipes, or if "git diff-tree" itself would suck up a lot of memory on a series
of huge patches.)

Maybe only pipe through limit_lines() if $maxlines > 0?

		M.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Add support for limiting number of lines generated in  messages by post-receive-email
  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-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
  1 sibling, 1 reply; 11+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-07-12 17:10 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: git

Just a nit on the format, which might help to get this accepted.

This patch has a 84 char subject line, the recommended maximum is 50
(used for --oneline). See Documents/SubmittingPatches.

On Thu, Jul 8, 2010 at 19:03, Kevin P. Fleming <kpfleming@digium.com> wrote:
> 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.
>
> This patch adds a new parameter to the post-receive-email hook script called
> 'maxlines', that defaults to 2048 if not specified. The entire message is
> filtered through a function that counts the number of lines generated
> (including headers), and any lines beyond the limit are suppressed; if any
> lines are suppressed, a final line is added indicating the number that
> were suppressed.

Maybe change the "We have", "This patch" etc. to use the "Changed"
wording recommended by Documents/SubmittingPatches?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Add support for limiting number of lines generated in messages by post-receive-email
  2010-07-12 16:47 ` Marc Branchaud
@ 2010-07-13 20:56   ` Kevin P. Fleming
  0 siblings, 0 replies; 11+ messages in thread
From: Kevin P. Fleming @ 2010-07-13 20:56 UTC (permalink / raw)
  Cc: git

On 07/12/2010 11:47 AM, Marc Branchaud wrote:
> On 10-07-08 03:03 PM, Kevin P. Fleming wrote:
>> 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.
>>
>> This patch adds a new parameter to the post-receive-email hook script called
>> 'maxlines', that defaults to 2048 if not specified. The entire message is
>> filtered through a function that counts the number of lines generated
>> (including headers), and any lines beyond the limit are suppressed; if any
>> lines are suppressed, a final line is added indicating the number that
>> were suppressed.
> 
> Hi Kevin,
> 
> I appreciate the work and the need you're addressing.  Thanks!
> 
> I do have a request though, which is to make this match the current
> (unlimited) behavior by default instead of imposing an arbitrary (although
> seemingly large) limit.

Done.

> I admit I don't have a strong reason for this, mainly just a desire to not
> force features on folks that don't need them.  IMHO the limit is a bit too
> hidden and likely to surprise someone at an inopportune time.  Plus what
> would someone do if they *want* no limit?
> 
> (FYI, we dealt with large-email syndrome by taking the diffs out of the
> emails and using a custom format to embed a gitweb URL instead.  Folks who
> care about the actual code change can browse the commit in gitweb.  This also
> helped make it easier for humans to parse the emails and the commits they
> contain.)

Yes, we'll probably include a gitweb URL as well.

> A couple more comments below...
> 
>> Signed-off-by: Kevin P. Fleming <kpfleming@digium.com>
>> ---
>>  contrib/hooks/post-receive-email |   31 ++++++++++++++++++++++++++++++-
>>  1 files changed, 30 insertions(+), 1 deletions(-)
>>
>> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
>> index 30ae63d..436c13f 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.maxlines
> 
> Why not call this something like "hooks.maxemaillines"?  "maxlines" is so
> generic that it might collide with something some other hook might use.

Changed.

> 
>> +#   The maximum number of lines that should be included in the generated
>> +#   email (including its headers). If not specified, defaults to 2048.
>> +#   Lines beyond the limit are suppressed and counted, and a final
>> +#   line is added indicating the number of suppressed lines.
>>  #
>>  # Notes
>>  # -----
>> @@ -642,6 +647,29 @@ show_new_revisions()
>>  }
>>  
>>  
>> +limit_lines()
>> +{
>> +    lines=0
>> +    skipped=0
>> +    limit=$(($1 - 2))
>> +    while IFS="" read line
>> +    do
>> +	lines=$((lines + 1))
>> +	if [ $lines -gt $limit ]
>> +	then
>> +	    skipped=$((skipped + 1))
>> +	else
>> +	    echo "$line"
>> +	fi
>> +    done
>> +    if [ $skipped -ne 0 ]
>> +    then
>> +	echo
>> +	echo "... $skipped lines suppressed ..."
>> +    fi
>> +}
>> +
>> +
>>  send_mail()
>>  {
>>  	if [ -n "$envelopesender" ]; then
>> @@ -679,6 +707,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.maxlines || echo '2048')
>>  
>>  # --- Main loop
>>  # Allow dual mode: run from the command line just like the update hook, or
>> @@ -691,6 +720,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
>>  else
>>  	while read oldrev newrev refname
>>  	do
>> -		generate_email $oldrev $newrev $refname | send_mail
>> +		generate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail
> 
> I'm a little concerned about the performance hit of piping the output through
> limit_lines(), which buffers all the lines in memory.  Folks who want large
> emails might get bitten by this.

The shell should start another process for limit_lines(), just as it
does for send_mail(), and thus only a small number of lines should ever
be in memory at once.

> 
> (That said, I don't know anything about the memory efficiency of the shell's
> pipes, or if "git diff-tree" itself would suck up a lot of memory on a series
> of huge patches.)
> 
> Maybe only pipe through limit_lines() if $maxlines > 0?

I've made this change as well; I'll post a new patch shortly.

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kfleming@digium.com
Check us out at www.digium.com & www.asterisk.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] Optional limit for number of lines generated by script
  2010-07-12 17:10 ` Ævar Arnfjörð Bjarmason
@ 2010-07-13 21:18   ` Kevin P. Fleming
  2010-07-13 21:43     ` Andreas Schwab
  2010-07-14 16:41     ` [PATCH] Optional limit for number of lines generated by script Marc Branchaud
  0 siblings, 2 replies; 11+ messages in thread
From: Kevin P. Fleming @ 2010-07-13 21:18 UTC (permalink / raw)
  To: git; +Cc: Kevin P. Fleming

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..d3b5fab 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 line
+    do
+	lines=$((lines + 1))
+	if [ $lines -gt $1 ]
+	then
+	    skipped=$((skipped + 1))
+	else
+	    echo "$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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] Optional limit for number of lines generated by script
  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       ` [PATCH] post-receive-email: optional message line count limit Kevin P. Fleming
  2010-07-14 16:41     ` [PATCH] Optional limit for number of lines generated by script Marc Branchaud
  1 sibling, 1 reply; 11+ messages in thread
From: Andreas Schwab @ 2010-07-13 21:43 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: git

"Kevin P. Fleming" <kpfleming@digium.com> writes:

> @@ -642,6 +647,27 @@ show_new_revisions()
>  }
>  
>  
> +limit_lines()
> +{
> +    lines=0
> +    skipped=0
> +    while IFS="" read line

You probably want to use read -r.

> +    do
> +	lines=$((lines + 1))
> +	if [ $lines -gt $1 ]
> +	then
> +	    skipped=$((skipped + 1))
> +	else
> +	    echo "$line"

            printf '%s\n' "$line"

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] Optional limit for number of lines generated by script
  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-14 16:41     ` Marc Branchaud
  1 sibling, 0 replies; 11+ messages in thread
From: Marc Branchaud @ 2010-07-14 16:41 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: git

Thanks for addressing my comments!

		M.


On 10-07-13 05:18 PM, Kevin P. Fleming wrote:
> 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..d3b5fab 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 line
> +    do
> +	lines=$((lines + 1))
> +	if [ $lines -gt $1 ]
> +	then
> +	    skipped=$((skipped + 1))
> +	else
> +	    echo "$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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] post-receive-email: optional message line count limit
  2010-07-13 21:43     ` Andreas Schwab
@ 2010-07-15 14:51       ` Kevin P. Fleming
  2010-07-15 17:36         ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin P. Fleming @ 2010-07-15 14:51 UTC (permalink / raw)
  To: git; +Cc: Kevin P. Fleming

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] post-receive-email: optional message line count limit
  2010-07-15 14:51       ` [PATCH] post-receive-email: optional message line count limit Kevin P. Fleming
@ 2010-07-15 17:36         ` Junio C Hamano
  2010-07-16 19:13           ` Kevin P. Fleming
  2010-07-16 19:16           ` Kevin P. Fleming
  0 siblings, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2010-07-15 17:36 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: git

"Kevin P. Fleming" <kpfleming@digium.com> writes:

> 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.
> ---

Sign-off?

> 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
> @@ -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

Since this is a contrib/ material, I should probably be not so picky about
it, but the style used in this script seems to be to use "; then" tacked
at the end on the same line as "if" is on.  Which is different from the
main scripted Porcelains in git.git, but you would want to be consistent
with the local convention around your code.

> +			skipped=$((skipped + 1))
> +		else
> +			printf "%s\n" "$line"
> +		fi
> +	done
> +	if [ $skipped -ne 0 ]
> +	then
> +		echo "... $skipped lines suppressed ..."
> +	fi
> +}

The above makes me wonder if the nicety of saying "we are not showing
everything; instead we skipped N lines" is really worth the trouble of the
shell loop.  Otherwise, a lot simpler:

	limit_lines ()
        {
        	head -n "$1"
	}

would be sufficient.  I dunno, and I don't deeply care either way.

> @@ -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

Hmm, the above made me wonder how the raw message needs to be generated
differently depending on maxlines and eyeball the common part for three
times to spot there is no difference.  I wouldn't have if it were written
this way:

	generate_email $oldrev $newrev $refname |
        if ...; then
        	send_mail
	else
        	limit_lines ... | send_mail
	fi

But more importantly, I have a suspicion that this patch is hooking into a
wrong place.  Look at what generate_email does.  It consists of calls to

 - generate_email_header, that gives the To:/Subject:/etc and the header
   boilerplate;

 - generate_*_*_email, that gives the body of the message; and

 - generate_email_footer, that gives the standard "-- " signature line.

You would never want to shorten the output so much that the header is cut
in the middle.  What you are trying to shorten is the body of the message,
so it would make a lot more sense to cut only the generate_*_*_email part.

IOW, shouldn't the patch be more like this?

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 30ae63d..d8964b6 100755
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -84,6 +84,7 @@ generate_email()
 	oldrev=$(git rev-parse $1)
 	newrev=$(git rev-parse $2)
 	refname="$3"
+	maxlines=$4
 
 	# --- Interpret
 	# 0000->1234 (create)
@@ -192,7 +193,12 @@ generate_email()
 		fn_name=atag
 		;;
 	esac
-	generate_${change_type}_${fn_name}_email
+	if [ -z "$maxlines" ]; then
+		generate_${change_type}_${fn_name}_email
+	else
+		generate_${change_type}_${fn_name}_email |
+		limit_lines $maxlines
+	fi
 
 	generate_email_footer
 }
@@ -691,6 +697,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
 else
 	while read oldrev newrev refname
 	do
-		generate_email $oldrev $newrev $refname | send_mail
+		generate_email $oldrev $newrev $refname $maxlines | send_mail
 	done
 fi

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] post-receive-email: optional message line count limit
  2010-07-15 17:36         ` Junio C Hamano
@ 2010-07-16 19:13           ` Kevin P. Fleming
  2010-07-16 19:16           ` Kevin P. Fleming
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin P. Fleming @ 2010-07-16 19:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On 07/15/2010 12:36 PM, Junio C Hamano wrote:
> "Kevin P. Fleming" <kpfleming@digium.com> writes:
> 
>> 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.
>> ---
> 
> Sign-off?

Oops... first-timer, I was under the mistaken impression that
git-send-email did that for me :-)

>> 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
>> @@ -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
> 
> Since this is a contrib/ material, I should probably be not so picky about
> it, but the style used in this script seems to be to use "; then" tacked
> at the end on the same line as "if" is on.  Which is different from the
> main scripted Porcelains in git.git, but you would want to be consistent
> with the local convention around your code.

Agreed, I'll change it to match the rest of the script.

> 
>> +			skipped=$((skipped + 1))
>> +		else
>> +			printf "%s\n" "$line"
>> +		fi
>> +	done
>> +	if [ $skipped -ne 0 ]
>> +	then
>> +		echo "... $skipped lines suppressed ..."
>> +	fi
>> +}
> 
> The above makes me wonder if the nicety of saying "we are not showing
> everything; instead we skipped N lines" is really worth the trouble of the
> shell loop.  Otherwise, a lot simpler:
> 
> 	limit_lines ()
>         {
>         	head -n "$1"
> 	}
> 
> would be sufficient.  I dunno, and I don't deeply care either way.

I think people would be concerned about 'missing' content if there was
no indicator that lines had been suppressed.

> 
>> @@ -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
> 
> Hmm, the above made me wonder how the raw message needs to be generated
> differently depending on maxlines and eyeball the common part for three
> times to spot there is no difference.  I wouldn't have if it were written
> this way:
> 
> 	generate_email $oldrev $newrev $refname |
>         if ...; then
>         	send_mail
> 	else
>         	limit_lines ... | send_mail
> 	fi
> 
> But more importantly, I have a suspicion that this patch is hooking into a
> wrong place.  Look at what generate_email does.  It consists of calls to
> 
>  - generate_email_header, that gives the To:/Subject:/etc and the header
>    boilerplate;
> 
>  - generate_*_*_email, that gives the body of the message; and
> 
>  - generate_email_footer, that gives the standard "-- " signature line.
> 
> You would never want to shorten the output so much that the header is cut
> in the middle.  What you are trying to shorten is the body of the message,
> so it would make a lot more sense to cut only the generate_*_*_email part.
> 
> IOW, shouldn't the patch be more like this?
> 
> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
> index 30ae63d..d8964b6 100755
> --- a/contrib/hooks/post-receive-email
> +++ b/contrib/hooks/post-receive-email
> @@ -84,6 +84,7 @@ generate_email()
>  	oldrev=$(git rev-parse $1)
>  	newrev=$(git rev-parse $2)
>  	refname="$3"
> +	maxlines=$4
>  
>  	# --- Interpret
>  	# 0000->1234 (create)
> @@ -192,7 +193,12 @@ generate_email()
>  		fn_name=atag
>  		;;
>  	esac
> -	generate_${change_type}_${fn_name}_email
> +	if [ -z "$maxlines" ]; then
> +		generate_${change_type}_${fn_name}_email
> +	else
> +		generate_${change_type}_${fn_name}_email |
> +		limit_lines $maxlines
> +	fi
>  
>  	generate_email_footer
>  }
> @@ -691,6 +697,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
>  else
>  	while read oldrev newrev refname
>  	do
> -		generate_email $oldrev $newrev $refname | send_mail
> +		generate_email $oldrev $newrev $refname $maxlines | send_mail
>  	done
>  fi

It should indeed; I'll post a new version in a minute that incorporates
your feedback. Thanks!

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kfleming@digium.com
Check us out at www.digium.com & www.asterisk.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] post-receive-email: optional message line count limit
  2010-07-15 17:36         ` Junio C Hamano
  2010-07-16 19:13           ` Kevin P. Fleming
@ 2010-07-16 19:16           ` Kevin P. Fleming
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin P. Fleming @ 2010-07-16 19:16 UTC (permalink / raw)
  To: git, gitster; +Cc: Kevin P. Fleming

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

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 30ae63d..11e51ec 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 body. 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
 # -----
@@ -84,6 +89,7 @@ generate_email()
 	oldrev=$(git rev-parse $1)
 	newrev=$(git rev-parse $2)
 	refname="$3"
+	maxlines=$4
 
 	# --- Interpret
 	# 0000->1234 (create)
@@ -192,7 +198,12 @@ generate_email()
 		fn_name=atag
 		;;
 	esac
-	generate_${change_type}_${fn_name}_email
+
+	if [ -z "$maxlines" ]; then
+		generate_${change_type}_${fn_name}_email
+	else
+		generate_${change_type}_${fn_name}_email | limit_lines $maxlines
+	fi
 
 	generate_email_footer
 }
@@ -642,6 +653,24 @@ 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 +708,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 +721,6 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
 else
 	while read oldrev newrev refname
 	do
-		generate_email $oldrev $newrev $refname | send_mail
+		generate_email $oldrev $newrev $refname $maxlines | send_mail
 	done
 fi
-- 
1.7.1.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-07-16 19:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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       ` [PATCH] post-receive-email: optional message line count limit Kevin P. Fleming
2010-07-15 17:36         ` 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

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).