{"thread":{"id":"24337","subject":"[PATCH] Add support for limiting number of lines generated in messages by post-receive-email","startedAt":"2010-07-08T19:03:10Z","lastAt":"2010-07-16T19:16:23Z","messageCount":11,"participants":["Kevin P. Fleming","Marc Branchaud","Ævar Arnfjörð Bjarmason","Andreas Schwab","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"145147","messageId":"1278615790-5433-1-git-send-email-kpfleming@digium.com","threadId":"24337","inReplyTo":null,"subject":"[PATCH] Add support for limiting number of lines generated in messages by post-receive-email","fromName":"Kevin P. Fleming","fromEmail":"kpfleming@digium.com","sentAt":"2010-07-08T19:03:10Z","receivedAt":"2010-07-08T19:03:10Z","isPatch":true,"sender":{"key":"kpfleming@digium.com","avatar":null},"body":"We have become used to the features of svnmailer when used with Subversion,\nand one of those useful features is that it can limit the maximum length\n(in lines) of a commit email message. This is terribly useful since once the\ngoes beyond a reasonable number of lines, nobody is going to read the remainder,\nand if they really want the entire contents of the commits, they can use\ngit itself to get them using the revision IDs present in the message already.\n\nThis patch adds a new parameter to the post-receive-email hook script called\n'maxlines', that defaults to 2048 if not specified. The entire message is\nfiltered through a function that counts the number of lines generated\n(including headers), and any lines beyond the limit are suppressed; if any\nlines are suppressed, a final line is added indicating the number that\nwere suppressed.\n\nSigned-off-by: Kevin P. Fleming <kpfleming@digium.com>\n---\n contrib/hooks/post-receive-email |   31 ++++++++++++++++++++++++++++++-\n 1 files changed, 30 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 30ae63d..436c13f 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -55,6 +55,11 @@\n #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n #   or printf.\n+# hooks.maxlines\n+#   The maximum number of lines that should be included in the generated\n+#   email (including its headers). If not specified, defaults to 2048.\n+#   Lines beyond the limit are suppressed and counted, and a final\n+#   line is added indicating the number of suppressed lines.\n #\n # Notes\n # -----\n@@ -642,6 +647,29 @@ show_new_revisions()\n }\n \n \n+limit_lines()\n+{\n+    lines=0\n+    skipped=0\n+    limit=$(($1 - 2))\n+    while IFS=\"\" read line\n+    do\n+\tlines=$((lines + 1))\n+\tif [ $lines -gt $limit ]\n+\tthen\n+\t    skipped=$((skipped + 1))\n+\telse\n+\t    echo \"$line\"\n+\tfi\n+    done\n+    if [ $skipped -ne 0 ]\n+    then\n+\techo\n+\techo \"... $skipped lines suppressed ...\"\n+    fi\n+}\n+\n+\n send_mail()\n {\n \tif [ -n \"$envelopesender\" ]; then\n@@ -679,6 +707,7 @@ announcerecipients=$(git config hooks.announcelist)\n envelopesender=$(git config hooks.envelopesender)\n emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n custom_showrev=$(git config hooks.showrev)\n+maxlines=$(git config hooks.maxlines || echo '2048')\n \n # --- Main loop\n # Allow dual mode: run from the command line just like the update hook, or\n@@ -691,6 +720,6 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n else\n \twhile read oldrev newrev refname\n \tdo\n-\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n \tdone\n fi\n-- \n1.7.1.1\n"},{"id":"145379","messageId":"4C3B4734.5070400@xiplink.com","threadId":"24337","inReplyTo":"1278615790-5433-1-git-send-email-kpfleming@digium.com","subject":"Re: [PATCH] Add support for limiting number of lines generated in messages by post-receive-email","fromName":"Marc Branchaud","fromEmail":"marcnarc@xiplink.com","sentAt":"2010-07-12T16:47:48Z","receivedAt":"2010-07-12T16:47:48Z","isPatch":true,"sender":{"key":"marcnarc@xiplink.com","avatar":"https://avatars.githubusercontent.com/u/14980203?v=4"},"body":"On 10-07-08 03:03 PM, Kevin P. Fleming wrote:\n> We have become used to the features of svnmailer when used with Subversion,\n> and one of those useful features is that it can limit the maximum length\n> (in lines) of a commit email message. This is terribly useful since once the\n> goes beyond a reasonable number of lines, nobody is going to read the remainder,\n> and if they really want the entire contents of the commits, they can use\n> git itself to get them using the revision IDs present in the message already.\n> \n> This patch adds a new parameter to the post-receive-email hook script called\n> 'maxlines', that defaults to 2048 if not specified. The entire message is\n> filtered through a function that counts the number of lines generated\n> (including headers), and any lines beyond the limit are suppressed; if any\n> lines are suppressed, a final line is added indicating the number that\n> were suppressed.\n\nHi Kevin,\n\nI appreciate the work and the need you're addressing.  Thanks!\n\nI do have a request though, which is to make this match the current\n(unlimited) behavior by default instead of imposing an arbitrary (although\nseemingly large) limit.\n\nI admit I don't have a strong reason for this, mainly just a desire to not\nforce features on folks that don't need them.  IMHO the limit is a bit too\nhidden and likely to surprise someone at an inopportune time.  Plus what\nwould someone do if they *want* no limit?\n\n(FYI, we dealt with large-email syndrome by taking the diffs out of the\nemails and using a custom format to embed a gitweb URL instead.  Folks who\ncare about the actual code change can browse the commit in gitweb.  This also\nhelped make it easier for humans to parse the emails and the commits they\ncontain.)\n\nA couple more comments below...\n\n> Signed-off-by: Kevin P. Fleming <kpfleming@digium.com>\n> ---\n>  contrib/hooks/post-receive-email |   31 ++++++++++++++++++++++++++++++-\n>  1 files changed, 30 insertions(+), 1 deletions(-)\n> \n> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n> index 30ae63d..436c13f 100755\n> --- a/contrib/hooks/post-receive-email\n> +++ b/contrib/hooks/post-receive-email\n> @@ -55,6 +55,11 @@\n>  #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n>  #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n>  #   or printf.\n> +# hooks.maxlines\n\nWhy not call this something like \"hooks.maxemaillines\"?  \"maxlines\" is so\ngeneric that it might collide with something some other hook might use.\n\n> +#   The maximum number of lines that should be included in the generated\n> +#   email (including its headers). If not specified, defaults to 2048.\n> +#   Lines beyond the limit are suppressed and counted, and a final\n> +#   line is added indicating the number of suppressed lines.\n>  #\n>  # Notes\n>  # -----\n> @@ -642,6 +647,29 @@ show_new_revisions()\n>  }\n>  \n>  \n> +limit_lines()\n> +{\n> +    lines=0\n> +    skipped=0\n> +    limit=$(($1 - 2))\n> +    while IFS=\"\" read line\n> +    do\n> +\tlines=$((lines + 1))\n> +\tif [ $lines -gt $limit ]\n> +\tthen\n> +\t    skipped=$((skipped + 1))\n> +\telse\n> +\t    echo \"$line\"\n> +\tfi\n> +    done\n> +    if [ $skipped -ne 0 ]\n> +    then\n> +\techo\n> +\techo \"... $skipped lines suppressed ...\"\n> +    fi\n> +}\n> +\n> +\n>  send_mail()\n>  {\n>  \tif [ -n \"$envelopesender\" ]; then\n> @@ -679,6 +707,7 @@ announcerecipients=$(git config hooks.announcelist)\n>  envelopesender=$(git config hooks.envelopesender)\n>  emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n>  custom_showrev=$(git config hooks.showrev)\n> +maxlines=$(git config hooks.maxlines || echo '2048')\n>  \n>  # --- Main loop\n>  # Allow dual mode: run from the command line just like the update hook, or\n> @@ -691,6 +720,6 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n>  else\n>  \twhile read oldrev newrev refname\n>  \tdo\n> -\t\tgenerate_email $oldrev $newrev $refname | send_mail\n> +\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n\nI'm a little concerned about the performance hit of piping the output through\nlimit_lines(), which buffers all the lines in memory.  Folks who want large\nemails might get bitten by this.\n\n(That said, I don't know anything about the memory efficiency of the shell's\npipes, or if \"git diff-tree\" itself would suck up a lot of memory on a series\nof huge patches.)\n\nMaybe only pipe through limit_lines() if $maxlines > 0?\n\n\t\tM.\n"},{"id":"145381","messageId":"AANLkTilVNhDl5OurCPpB68buvQZPAulkuEye0FUTyThP@mail.gmail.com","threadId":"24337","inReplyTo":"1278615790-5433-1-git-send-email-kpfleming@digium.com","subject":"Re: [PATCH] Add support for limiting number of lines generated in messages by post-receive-email","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-12T17:10:06Z","receivedAt":"2010-07-12T17:10:06Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Just a nit on the format, which might help to get this accepted.\n\nThis patch has a 84 char subject line, the recommended maximum is 50\n(used for --oneline). See Documents/SubmittingPatches.\n\nOn Thu, Jul 8, 2010 at 19:03, Kevin P. Fleming <kpfleming@digium.com> wrote:\n> We have become used to the features of svnmailer when used with Subversion,\n> and one of those useful features is that it can limit the maximum length\n> (in lines) of a commit email message. This is terribly useful since once the\n> goes beyond a reasonable number of lines, nobody is going to read the remainder,\n> and if they really want the entire contents of the commits, they can use\n> git itself to get them using the revision IDs present in the message already.\n>\n> This patch adds a new parameter to the post-receive-email hook script called\n> 'maxlines', that defaults to 2048 if not specified. The entire message is\n> filtered through a function that counts the number of lines generated\n> (including headers), and any lines beyond the limit are suppressed; if any\n> lines are suppressed, a final line is added indicating the number that\n> were suppressed.\n\nMaybe change the \"We have\", \"This patch\" etc. to use the \"Changed\"\nwording recommended by Documents/SubmittingPatches?\n"},{"id":"145461","messageId":"4C3CD2FF.4040000@digium.com","threadId":"24337","inReplyTo":"4C3B4734.5070400@xiplink.com","subject":"Re: [PATCH] Add support for limiting number of lines generated in messages by post-receive-email","fromName":"Kevin P. Fleming","fromEmail":"kpfleming@digium.com","sentAt":"2010-07-13T20:56:31Z","receivedAt":"2010-07-13T20:56:31Z","isPatch":true,"sender":{"key":"kpfleming@digium.com","avatar":null},"body":"On 07/12/2010 11:47 AM, Marc Branchaud wrote:\n> On 10-07-08 03:03 PM, Kevin P. Fleming wrote:\n>> We have become used to the features of svnmailer when used with Subversion,\n>> and one of those useful features is that it can limit the maximum length\n>> (in lines) of a commit email message. This is terribly useful since once the\n>> goes beyond a reasonable number of lines, nobody is going to read the remainder,\n>> and if they really want the entire contents of the commits, they can use\n>> git itself to get them using the revision IDs present in the message already.\n>>\n>> This patch adds a new parameter to the post-receive-email hook script called\n>> 'maxlines', that defaults to 2048 if not specified. The entire message is\n>> filtered through a function that counts the number of lines generated\n>> (including headers), and any lines beyond the limit are suppressed; if any\n>> lines are suppressed, a final line is added indicating the number that\n>> were suppressed.\n> \n> Hi Kevin,\n> \n> I appreciate the work and the need you're addressing.  Thanks!\n> \n> I do have a request though, which is to make this match the current\n> (unlimited) behavior by default instead of imposing an arbitrary (although\n> seemingly large) limit.\n\nDone.\n\n> I admit I don't have a strong reason for this, mainly just a desire to not\n> force features on folks that don't need them.  IMHO the limit is a bit too\n> hidden and likely to surprise someone at an inopportune time.  Plus what\n> would someone do if they *want* no limit?\n> \n> (FYI, we dealt with large-email syndrome by taking the diffs out of the\n> emails and using a custom format to embed a gitweb URL instead.  Folks who\n> care about the actual code change can browse the commit in gitweb.  This also\n> helped make it easier for humans to parse the emails and the commits they\n> contain.)\n\nYes, we'll probably include a gitweb URL as well.\n\n> A couple more comments below...\n> \n>> Signed-off-by: Kevin P. Fleming <kpfleming@digium.com>\n>> ---\n>>  contrib/hooks/post-receive-email |   31 ++++++++++++++++++++++++++++++-\n>>  1 files changed, 30 insertions(+), 1 deletions(-)\n>>\n>> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n>> index 30ae63d..436c13f 100755\n>> --- a/contrib/hooks/post-receive-email\n>> +++ b/contrib/hooks/post-receive-email\n>> @@ -55,6 +55,11 @@\n>>  #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n>>  #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n>>  #   or printf.\n>> +# hooks.maxlines\n> \n> Why not call this something like \"hooks.maxemaillines\"?  \"maxlines\" is so\n> generic that it might collide with something some other hook might use.\n\nChanged.\n\n> \n>> +#   The maximum number of lines that should be included in the generated\n>> +#   email (including its headers). If not specified, defaults to 2048.\n>> +#   Lines beyond the limit are suppressed and counted, and a final\n>> +#   line is added indicating the number of suppressed lines.\n>>  #\n>>  # Notes\n>>  # -----\n>> @@ -642,6 +647,29 @@ show_new_revisions()\n>>  }\n>>  \n>>  \n>> +limit_lines()\n>> +{\n>> +    lines=0\n>> +    skipped=0\n>> +    limit=$(($1 - 2))\n>> +    while IFS=\"\" read line\n>> +    do\n>> +\tlines=$((lines + 1))\n>> +\tif [ $lines -gt $limit ]\n>> +\tthen\n>> +\t    skipped=$((skipped + 1))\n>> +\telse\n>> +\t    echo \"$line\"\n>> +\tfi\n>> +    done\n>> +    if [ $skipped -ne 0 ]\n>> +    then\n>> +\techo\n>> +\techo \"... $skipped lines suppressed ...\"\n>> +    fi\n>> +}\n>> +\n>> +\n>>  send_mail()\n>>  {\n>>  \tif [ -n \"$envelopesender\" ]; then\n>> @@ -679,6 +707,7 @@ announcerecipients=$(git config hooks.announcelist)\n>>  envelopesender=$(git config hooks.envelopesender)\n>>  emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n>>  custom_showrev=$(git config hooks.showrev)\n>> +maxlines=$(git config hooks.maxlines || echo '2048')\n>>  \n>>  # --- Main loop\n>>  # Allow dual mode: run from the command line just like the update hook, or\n>> @@ -691,6 +720,6 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n>>  else\n>>  \twhile read oldrev newrev refname\n>>  \tdo\n>> -\t\tgenerate_email $oldrev $newrev $refname | send_mail\n>> +\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n> \n> I'm a little concerned about the performance hit of piping the output through\n> limit_lines(), which buffers all the lines in memory.  Folks who want large\n> emails might get bitten by this.\n\nThe shell should start another process for limit_lines(), just as it\ndoes for send_mail(), and thus only a small number of lines should ever\nbe in memory at once.\n\n> \n> (That said, I don't know anything about the memory efficiency of the shell's\n> pipes, or if \"git diff-tree\" itself would suck up a lot of memory on a series\n> of huge patches.)\n> \n> Maybe only pipe through limit_lines() if $maxlines > 0?\n\nI've made this change as well; I'll post a new patch shortly.\n\n-- \nKevin P. Fleming\nDigium, Inc. | Director of Software Technologies\n445 Jan Davis Drive NW - Huntsville, AL 35806 - USA\nskype: kpfleming | jabber: kfleming@digium.com\nCheck us out at www.digium.com & www.asterisk.org\n"},{"id":"145465","messageId":"1279055909-4340-1-git-send-email-kpfleming@digium.com","threadId":"24337","inReplyTo":"AANLkTilVNhDl5OurCPpB68buvQZPAulkuEye0FUTyThP@mail.gmail.com","subject":"[PATCH] Optional limit for number of lines generated by script","fromName":"Kevin P. Fleming","fromEmail":"kpfleming@digium.com","sentAt":"2010-07-13T21:18:29Z","receivedAt":"2010-07-13T21:18:29Z","isPatch":true,"sender":{"key":"kpfleming@digium.com","avatar":null},"body":"We have become used to the features of svnmailer when used with Subversion,\nand one of those useful features is that it can limit the maximum length\n(in lines) of a commit email message. This is terribly useful since once the\ngoes beyond a reasonable number of lines, nobody is going to read the remainder,\nand if they really want the entire contents of the commits, they can use\ngit itself to get them using the revision IDs present in the message already.\n\nChange the post-receive-email script to respond to an 'emailmaxlines' config key\nwhich, if specified, will limit the number of lines generated (including\nheaders); any lines beyond the limit are suppressed, and a final line is added\nindicating the number that were suppressed.\n---\n contrib/hooks/post-receive-email |   33 ++++++++++++++++++++++++++++++++-\n 1 files changed, 32 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 30ae63d..d3b5fab 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -55,6 +55,11 @@\n #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n #   or printf.\n+# hooks.emailmaxlines\n+#   The maximum number of lines that should be included in the generated\n+#   email (including its headers). If not specified, there is no limit.\n+#   Lines beyond the limit are suppressed and counted, and a final\n+#   line is added indicating the number of suppressed lines.\n #\n # Notes\n # -----\n@@ -642,6 +647,27 @@ show_new_revisions()\n }\n \n \n+limit_lines()\n+{\n+    lines=0\n+    skipped=0\n+    while IFS=\"\" read line\n+    do\n+\tlines=$((lines + 1))\n+\tif [ $lines -gt $1 ]\n+\tthen\n+\t    skipped=$((skipped + 1))\n+\telse\n+\t    echo \"$line\"\n+\tfi\n+    done\n+    if [ $skipped -ne 0 ]\n+    then\n+\techo \"... $skipped lines suppressed ...\"\n+    fi\n+}\n+\n+\n send_mail()\n {\n \tif [ -n \"$envelopesender\" ]; then\n@@ -679,6 +705,7 @@ announcerecipients=$(git config hooks.announcelist)\n envelopesender=$(git config hooks.envelopesender)\n emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n custom_showrev=$(git config hooks.showrev)\n+maxlines=$(git config hooks.emailmaxlines)\n \n # --- Main loop\n # Allow dual mode: run from the command line just like the update hook, or\n@@ -691,6 +718,10 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n else\n \twhile read oldrev newrev refname\n \tdo\n-\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\tif [ -z \"$maxlines\" ]; then\n+\t\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\telse\n+\t\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n+\t\tfi\n \tdone\n fi\n-- \n1.7.1.1\n"},{"id":"145476","messageId":"m2vd8jhxbd.fsf@igel.home","threadId":"24337","inReplyTo":"1279055909-4340-1-git-send-email-kpfleming@digium.com","subject":"Re: [PATCH] Optional limit for number of lines generated by script","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2010-07-13T21:43:50Z","receivedAt":"2010-07-13T21:43:50Z","isPatch":true,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"\"Kevin P. Fleming\" <kpfleming@digium.com> writes:\n\n> @@ -642,6 +647,27 @@ show_new_revisions()\n>  }\n>  \n>  \n> +limit_lines()\n> +{\n> +    lines=0\n> +    skipped=0\n> +    while IFS=\"\" read line\n\nYou probably want to use read -r.\n\n> +    do\n> +\tlines=$((lines + 1))\n> +\tif [ $lines -gt $1 ]\n> +\tthen\n> +\t    skipped=$((skipped + 1))\n> +\telse\n> +\t    echo \"$line\"\n\n            printf '%s\\n' \"$line\"\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"145556","messageId":"4C3DE8CD.5060103@xiplink.com","threadId":"24337","inReplyTo":"1279055909-4340-1-git-send-email-kpfleming@digium.com","subject":"Re: [PATCH] Optional limit for number of lines generated by script","fromName":"Marc Branchaud","fromEmail":"marcnarc@xiplink.com","sentAt":"2010-07-14T16:41:49Z","receivedAt":"2010-07-14T16:41:49Z","isPatch":true,"sender":{"key":"marcnarc@xiplink.com","avatar":"https://avatars.githubusercontent.com/u/14980203?v=4"},"body":"Thanks for addressing my comments!\n\n\t\tM.\n\n\nOn 10-07-13 05:18 PM, Kevin P. Fleming wrote:\n> We have become used to the features of svnmailer when used with Subversion,\n> and one of those useful features is that it can limit the maximum length\n> (in lines) of a commit email message. This is terribly useful since once the\n> goes beyond a reasonable number of lines, nobody is going to read the remainder,\n> and if they really want the entire contents of the commits, they can use\n> git itself to get them using the revision IDs present in the message already.\n> \n> Change the post-receive-email script to respond to an 'emailmaxlines' config key\n> which, if specified, will limit the number of lines generated (including\n> headers); any lines beyond the limit are suppressed, and a final line is added\n> indicating the number that were suppressed.\n> ---\n>  contrib/hooks/post-receive-email |   33 ++++++++++++++++++++++++++++++++-\n>  1 files changed, 32 insertions(+), 1 deletions(-)\n> \n> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n> index 30ae63d..d3b5fab 100755\n> --- a/contrib/hooks/post-receive-email\n> +++ b/contrib/hooks/post-receive-email\n> @@ -55,6 +55,11 @@\n>  #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n>  #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n>  #   or printf.\n> +# hooks.emailmaxlines\n> +#   The maximum number of lines that should be included in the generated\n> +#   email (including its headers). If not specified, there is no limit.\n> +#   Lines beyond the limit are suppressed and counted, and a final\n> +#   line is added indicating the number of suppressed lines.\n>  #\n>  # Notes\n>  # -----\n> @@ -642,6 +647,27 @@ show_new_revisions()\n>  }\n>  \n>  \n> +limit_lines()\n> +{\n> +    lines=0\n> +    skipped=0\n> +    while IFS=\"\" read line\n> +    do\n> +\tlines=$((lines + 1))\n> +\tif [ $lines -gt $1 ]\n> +\tthen\n> +\t    skipped=$((skipped + 1))\n> +\telse\n> +\t    echo \"$line\"\n> +\tfi\n> +    done\n> +    if [ $skipped -ne 0 ]\n> +    then\n> +\techo \"... $skipped lines suppressed ...\"\n> +    fi\n> +}\n> +\n> +\n>  send_mail()\n>  {\n>  \tif [ -n \"$envelopesender\" ]; then\n> @@ -679,6 +705,7 @@ announcerecipients=$(git config hooks.announcelist)\n>  envelopesender=$(git config hooks.envelopesender)\n>  emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n>  custom_showrev=$(git config hooks.showrev)\n> +maxlines=$(git config hooks.emailmaxlines)\n>  \n>  # --- Main loop\n>  # Allow dual mode: run from the command line just like the update hook, or\n> @@ -691,6 +718,10 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n>  else\n>  \twhile read oldrev newrev refname\n>  \tdo\n> -\t\tgenerate_email $oldrev $newrev $refname | send_mail\n> +\t\tif [ -z \"$maxlines\" ]; then\n> +\t\t\tgenerate_email $oldrev $newrev $refname | send_mail\n> +\t\telse\n> +\t\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n> +\t\tfi\n>  \tdone\n>  fi\n"},{"id":"145626","messageId":"1279205516-3302-1-git-send-email-kpfleming@digium.com","threadId":"24337","inReplyTo":"m2vd8jhxbd.fsf@igel.home","subject":"[PATCH] post-receive-email: optional message line count limit","fromName":"Kevin P. Fleming","fromEmail":"kpfleming@digium.com","sentAt":"2010-07-15T14:51:56Z","receivedAt":"2010-07-15T14:51:56Z","isPatch":true,"sender":{"key":"kpfleming@digium.com","avatar":null},"body":"We have become used to the features of svnmailer when used with Subversion,\nand one of those useful features is that it can limit the maximum length\n(in lines) of a commit email message. This is terribly useful since once the\ngoes beyond a reasonable number of lines, nobody is going to read the remainder,\nand if they really want the entire contents of the commits, they can use\ngit itself to get them using the revision IDs present in the message already.\n\nChange the post-receive-email script to respond to an 'emailmaxlines' config key\nwhich, if specified, will limit the number of lines generated (including\nheaders); any lines beyond the limit are suppressed, and a final line is added\nindicating the number that were suppressed.\n---\n contrib/hooks/post-receive-email |   33 ++++++++++++++++++++++++++++++++-\n 1 files changed, 32 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 30ae63d..4dc85c2 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -55,6 +55,11 @@\n #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n #   or printf.\n+# hooks.emailmaxlines\n+#   The maximum number of lines that should be included in the generated\n+#   email (including its headers). If not specified, there is no limit.\n+#   Lines beyond the limit are suppressed and counted, and a final\n+#   line is added indicating the number of suppressed lines.\n #\n # Notes\n # -----\n@@ -642,6 +647,27 @@ show_new_revisions()\n }\n \n \n+limit_lines()\n+{\n+\tlines=0\n+\tskipped=0\n+\twhile IFS=\"\" read -r line\n+\tdo\n+\t\tlines=$((lines + 1))\n+\t\tif [ $lines -gt $1 ]\n+\t\tthen\n+\t\t\tskipped=$((skipped + 1))\n+\t\telse\n+\t\t\tprintf \"%s\\n\" \"$line\"\n+\t\tfi\n+\tdone\n+\tif [ $skipped -ne 0 ]\n+\tthen\n+\t\techo \"... $skipped lines suppressed ...\"\n+\tfi\n+}\n+\n+\n send_mail()\n {\n \tif [ -n \"$envelopesender\" ]; then\n@@ -679,6 +705,7 @@ announcerecipients=$(git config hooks.announcelist)\n envelopesender=$(git config hooks.envelopesender)\n emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n custom_showrev=$(git config hooks.showrev)\n+maxlines=$(git config hooks.emailmaxlines)\n \n # --- Main loop\n # Allow dual mode: run from the command line just like the update hook, or\n@@ -691,6 +718,10 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n else\n \twhile read oldrev newrev refname\n \tdo\n-\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\tif [ -z \"$maxlines\" ]; then\n+\t\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\telse\n+\t\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n+\t\tfi\n \tdone\n fi\n-- \n1.7.1.1\n"},{"id":"145640","messageId":"7v1vb4wsso.fsf@alter.siamese.dyndns.org","threadId":"24337","inReplyTo":"1279205516-3302-1-git-send-email-kpfleming@digium.com","subject":"Re: [PATCH] post-receive-email: optional message line count limit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-07-15T17:36:55Z","receivedAt":"2010-07-15T17:36:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Kevin P. Fleming\" <kpfleming@digium.com> writes:\n\n> We have become used to the features of svnmailer when used with Subversion,\n> and one of those useful features is that it can limit the maximum length\n> (in lines) of a commit email message. This is terribly useful since once the\n> goes beyond a reasonable number of lines, nobody is going to read the remainder,\n> and if they really want the entire contents of the commits, they can use\n> git itself to get them using the revision IDs present in the message already.\n>\n> Change the post-receive-email script to respond to an 'emailmaxlines' config key\n> which, if specified, will limit the number of lines generated (including\n> headers); any lines beyond the limit are suppressed, and a final line is added\n> indicating the number that were suppressed.\n> ---\n\nSign-off?\n\n> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n> index 30ae63d..4dc85c2 100755\n> --- a/contrib/hooks/post-receive-email\n> +++ b/contrib/hooks/post-receive-email\n> @@ -642,6 +647,27 @@ show_new_revisions()\n>  }\n>  \n>  \n> +limit_lines()\n> +{\n> +\tlines=0\n> +\tskipped=0\n> +\twhile IFS=\"\" read -r line\n> +\tdo\n> +\t\tlines=$((lines + 1))\n> +\t\tif [ $lines -gt $1 ]\n> +\t\tthen\n\nSince this is a contrib/ material, I should probably be not so picky about\nit, but the style used in this script seems to be to use \"; then\" tacked\nat the end on the same line as \"if\" is on.  Which is different from the\nmain scripted Porcelains in git.git, but you would want to be consistent\nwith the local convention around your code.\n\n> +\t\t\tskipped=$((skipped + 1))\n> +\t\telse\n> +\t\t\tprintf \"%s\\n\" \"$line\"\n> +\t\tfi\n> +\tdone\n> +\tif [ $skipped -ne 0 ]\n> +\tthen\n> +\t\techo \"... $skipped lines suppressed ...\"\n> +\tfi\n> +}\n\nThe above makes me wonder if the nicety of saying \"we are not showing\neverything; instead we skipped N lines\" is really worth the trouble of the\nshell loop.  Otherwise, a lot simpler:\n\n\tlimit_lines ()\n        {\n        \thead -n \"$1\"\n\t}\n\nwould be sufficient.  I dunno, and I don't deeply care either way.\n\n> @@ -679,6 +705,7 @@ announcerecipients=$(git config hooks.announcelist)\n>  envelopesender=$(git config hooks.envelopesender)\n>  emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n>  custom_showrev=$(git config hooks.showrev)\n> +maxlines=$(git config hooks.emailmaxlines)\n>  \n>  # --- Main loop\n>  # Allow dual mode: run from the command line just like the update hook, or\n> @@ -691,6 +718,10 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n>  else\n>  \twhile read oldrev newrev refname\n>  \tdo\n> -\t\tgenerate_email $oldrev $newrev $refname | send_mail\n> +\t\tif [ -z \"$maxlines\" ]; then\n> +\t\t\tgenerate_email $oldrev $newrev $refname | send_mail\n> +\t\telse\n> +\t\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n> +\t\tfi\n\nHmm, the above made me wonder how the raw message needs to be generated\ndifferently depending on maxlines and eyeball the common part for three\ntimes to spot there is no difference.  I wouldn't have if it were written\nthis way:\n\n\tgenerate_email $oldrev $newrev $refname |\n        if ...; then\n        \tsend_mail\n\telse\n        \tlimit_lines ... | send_mail\n\tfi\n\nBut more importantly, I have a suspicion that this patch is hooking into a\nwrong place.  Look at what generate_email does.  It consists of calls to\n\n - generate_email_header, that gives the To:/Subject:/etc and the header\n   boilerplate;\n\n - generate_*_*_email, that gives the body of the message; and\n\n - generate_email_footer, that gives the standard \"-- \" signature line.\n\nYou would never want to shorten the output so much that the header is cut\nin the middle.  What you are trying to shorten is the body of the message,\nso it would make a lot more sense to cut only the generate_*_*_email part.\n\nIOW, shouldn't the patch be more like this?\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 30ae63d..d8964b6 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -84,6 +84,7 @@ generate_email()\n \toldrev=$(git rev-parse $1)\n \tnewrev=$(git rev-parse $2)\n \trefname=\"$3\"\n+\tmaxlines=$4\n \n \t# --- Interpret\n \t# 0000->1234 (create)\n@@ -192,7 +193,12 @@ generate_email()\n \t\tfn_name=atag\n \t\t;;\n \tesac\n-\tgenerate_${change_type}_${fn_name}_email\n+\tif [ -z \"$maxlines\" ]; then\n+\t\tgenerate_${change_type}_${fn_name}_email\n+\telse\n+\t\tgenerate_${change_type}_${fn_name}_email |\n+\t\tlimit_lines $maxlines\n+\tfi\n \n \tgenerate_email_footer\n }\n@@ -691,6 +697,6 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n else\n \twhile read oldrev newrev refname\n \tdo\n-\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\tgenerate_email $oldrev $newrev $refname $maxlines | send_mail\n \tdone\n fi\n"},{"id":"145703","messageId":"4C40AF76.80709@digium.com","threadId":"24337","inReplyTo":"7v1vb4wsso.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] post-receive-email: optional message line count limit","fromName":"Kevin P. Fleming","fromEmail":"kpfleming@digium.com","sentAt":"2010-07-16T19:13:58Z","receivedAt":"2010-07-16T19:13:58Z","isPatch":true,"sender":{"key":"kpfleming@digium.com","avatar":null},"body":"On 07/15/2010 12:36 PM, Junio C Hamano wrote:\n> \"Kevin P. Fleming\" <kpfleming@digium.com> writes:\n> \n>> We have become used to the features of svnmailer when used with Subversion,\n>> and one of those useful features is that it can limit the maximum length\n>> (in lines) of a commit email message. This is terribly useful since once the\n>> goes beyond a reasonable number of lines, nobody is going to read the remainder,\n>> and if they really want the entire contents of the commits, they can use\n>> git itself to get them using the revision IDs present in the message already.\n>>\n>> Change the post-receive-email script to respond to an 'emailmaxlines' config key\n>> which, if specified, will limit the number of lines generated (including\n>> headers); any lines beyond the limit are suppressed, and a final line is added\n>> indicating the number that were suppressed.\n>> ---\n> \n> Sign-off?\n\nOops... first-timer, I was under the mistaken impression that\ngit-send-email did that for me :-)\n\n>> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n>> index 30ae63d..4dc85c2 100755\n>> --- a/contrib/hooks/post-receive-email\n>> +++ b/contrib/hooks/post-receive-email\n>> @@ -642,6 +647,27 @@ show_new_revisions()\n>>  }\n>>  \n>>  \n>> +limit_lines()\n>> +{\n>> +\tlines=0\n>> +\tskipped=0\n>> +\twhile IFS=\"\" read -r line\n>> +\tdo\n>> +\t\tlines=$((lines + 1))\n>> +\t\tif [ $lines -gt $1 ]\n>> +\t\tthen\n> \n> Since this is a contrib/ material, I should probably be not so picky about\n> it, but the style used in this script seems to be to use \"; then\" tacked\n> at the end on the same line as \"if\" is on.  Which is different from the\n> main scripted Porcelains in git.git, but you would want to be consistent\n> with the local convention around your code.\n\nAgreed, I'll change it to match the rest of the script.\n\n> \n>> +\t\t\tskipped=$((skipped + 1))\n>> +\t\telse\n>> +\t\t\tprintf \"%s\\n\" \"$line\"\n>> +\t\tfi\n>> +\tdone\n>> +\tif [ $skipped -ne 0 ]\n>> +\tthen\n>> +\t\techo \"... $skipped lines suppressed ...\"\n>> +\tfi\n>> +}\n> \n> The above makes me wonder if the nicety of saying \"we are not showing\n> everything; instead we skipped N lines\" is really worth the trouble of the\n> shell loop.  Otherwise, a lot simpler:\n> \n> \tlimit_lines ()\n>         {\n>         \thead -n \"$1\"\n> \t}\n> \n> would be sufficient.  I dunno, and I don't deeply care either way.\n\nI think people would be concerned about 'missing' content if there was\nno indicator that lines had been suppressed.\n\n> \n>> @@ -679,6 +705,7 @@ announcerecipients=$(git config hooks.announcelist)\n>>  envelopesender=$(git config hooks.envelopesender)\n>>  emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n>>  custom_showrev=$(git config hooks.showrev)\n>> +maxlines=$(git config hooks.emailmaxlines)\n>>  \n>>  # --- Main loop\n>>  # Allow dual mode: run from the command line just like the update hook, or\n>> @@ -691,6 +718,10 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n>>  else\n>>  \twhile read oldrev newrev refname\n>>  \tdo\n>> -\t\tgenerate_email $oldrev $newrev $refname | send_mail\n>> +\t\tif [ -z \"$maxlines\" ]; then\n>> +\t\t\tgenerate_email $oldrev $newrev $refname | send_mail\n>> +\t\telse\n>> +\t\t\tgenerate_email $oldrev $newrev $refname | limit_lines $maxlines | send_mail\n>> +\t\tfi\n> \n> Hmm, the above made me wonder how the raw message needs to be generated\n> differently depending on maxlines and eyeball the common part for three\n> times to spot there is no difference.  I wouldn't have if it were written\n> this way:\n> \n> \tgenerate_email $oldrev $newrev $refname |\n>         if ...; then\n>         \tsend_mail\n> \telse\n>         \tlimit_lines ... | send_mail\n> \tfi\n> \n> But more importantly, I have a suspicion that this patch is hooking into a\n> wrong place.  Look at what generate_email does.  It consists of calls to\n> \n>  - generate_email_header, that gives the To:/Subject:/etc and the header\n>    boilerplate;\n> \n>  - generate_*_*_email, that gives the body of the message; and\n> \n>  - generate_email_footer, that gives the standard \"-- \" signature line.\n> \n> You would never want to shorten the output so much that the header is cut\n> in the middle.  What you are trying to shorten is the body of the message,\n> so it would make a lot more sense to cut only the generate_*_*_email part.\n> \n> IOW, shouldn't the patch be more like this?\n> \n> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n> index 30ae63d..d8964b6 100755\n> --- a/contrib/hooks/post-receive-email\n> +++ b/contrib/hooks/post-receive-email\n> @@ -84,6 +84,7 @@ generate_email()\n>  \toldrev=$(git rev-parse $1)\n>  \tnewrev=$(git rev-parse $2)\n>  \trefname=\"$3\"\n> +\tmaxlines=$4\n>  \n>  \t# --- Interpret\n>  \t# 0000->1234 (create)\n> @@ -192,7 +193,12 @@ generate_email()\n>  \t\tfn_name=atag\n>  \t\t;;\n>  \tesac\n> -\tgenerate_${change_type}_${fn_name}_email\n> +\tif [ -z \"$maxlines\" ]; then\n> +\t\tgenerate_${change_type}_${fn_name}_email\n> +\telse\n> +\t\tgenerate_${change_type}_${fn_name}_email |\n> +\t\tlimit_lines $maxlines\n> +\tfi\n>  \n>  \tgenerate_email_footer\n>  }\n> @@ -691,6 +697,6 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n>  else\n>  \twhile read oldrev newrev refname\n>  \tdo\n> -\t\tgenerate_email $oldrev $newrev $refname | send_mail\n> +\t\tgenerate_email $oldrev $newrev $refname $maxlines | send_mail\n>  \tdone\n>  fi\n\nIt should indeed; I'll post a new version in a minute that incorporates\nyour feedback. Thanks!\n\n-- \nKevin P. Fleming\nDigium, Inc. | Director of Software Technologies\n445 Jan Davis Drive NW - Huntsville, AL 35806 - USA\nskype: kpfleming | jabber: kfleming@digium.com\nCheck us out at www.digium.com & www.asterisk.org\n"},{"id":"145705","messageId":"1279307783-4859-1-git-send-email-kpfleming@digium.com","threadId":"24337","inReplyTo":"7v1vb4wsso.fsf@alter.siamese.dyndns.org","subject":"[PATCH] post-receive-email: optional message line count limit","fromName":"Kevin P. Fleming","fromEmail":"kpfleming@digium.com","sentAt":"2010-07-16T19:16:23Z","receivedAt":"2010-07-16T19:16:23Z","isPatch":true,"sender":{"key":"kpfleming@digium.com","avatar":null},"body":"We have become used to the features of svnmailer when used with Subversion,\nand one of those useful features is that it can limit the maximum length\n(in lines) of a commit email message. This is terribly useful since once the\ngoes beyond a reasonable number of lines, nobody is going to read the remainder,\nand if they really want the entire contents of the commits, they can use\ngit itself to get them using the revision IDs present in the message already.\n\nChange the post-receive-email script to respond to an 'emailmaxlines' config key\nwhich, if specified, will limit the number of lines generated (including\nheaders); any lines beyond the limit are suppressed, and a final line is added\nindicating the number that were suppressed.\n\nSigned-off-by: Kevin P. Fleming <kpfleming@digium.com>\n---\n contrib/hooks/post-receive-email |   34 ++++++++++++++++++++++++++++++++--\n 1 files changed, 32 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 30ae63d..11e51ec 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -55,6 +55,11 @@\n #     \"t=%s; printf 'http://.../?id=%%s' \\$t; echo;echo; git show -C \\$t; echo\"\n #   Be careful if \"...\" contains things that will be expanded by shell \"eval\"\n #   or printf.\n+# hooks.emailmaxlines\n+#   The maximum number of lines that should be included in the generated\n+#   email body. If not specified, there is no limit.\n+#   Lines beyond the limit are suppressed and counted, and a final\n+#   line is added indicating the number of suppressed lines.\n #\n # Notes\n # -----\n@@ -84,6 +89,7 @@ generate_email()\n \toldrev=$(git rev-parse $1)\n \tnewrev=$(git rev-parse $2)\n \trefname=\"$3\"\n+\tmaxlines=$4\n \n \t# --- Interpret\n \t# 0000->1234 (create)\n@@ -192,7 +198,12 @@ generate_email()\n \t\tfn_name=atag\n \t\t;;\n \tesac\n-\tgenerate_${change_type}_${fn_name}_email\n+\n+\tif [ -z \"$maxlines\" ]; then\n+\t\tgenerate_${change_type}_${fn_name}_email\n+\telse\n+\t\tgenerate_${change_type}_${fn_name}_email | limit_lines $maxlines\n+\tfi\n \n \tgenerate_email_footer\n }\n@@ -642,6 +653,24 @@ show_new_revisions()\n }\n \n \n+limit_lines()\n+{\n+\tlines=0\n+\tskipped=0\n+\twhile IFS=\"\" read -r line; do\n+\t\tlines=$((lines + 1))\n+\t\tif [ $lines -gt $1 ]; then\n+\t\t\tskipped=$((skipped + 1))\n+\t\telse\n+\t\t\tprintf \"%s\\n\" \"$line\"\n+\t\tfi\n+\tdone\n+\tif [ $skipped -ne 0 ]; then\n+\t\techo \"... $skipped lines suppressed ...\"\n+\tfi\n+}\n+\n+\n send_mail()\n {\n \tif [ -n \"$envelopesender\" ]; then\n@@ -679,6 +708,7 @@ announcerecipients=$(git config hooks.announcelist)\n envelopesender=$(git config hooks.envelopesender)\n emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n custom_showrev=$(git config hooks.showrev)\n+maxlines=$(git config hooks.emailmaxlines)\n \n # --- Main loop\n # Allow dual mode: run from the command line just like the update hook, or\n@@ -691,6 +721,6 @@ if [ -n \"$1\" -a -n \"$2\" -a -n \"$3\" ]; then\n else\n \twhile read oldrev newrev refname\n \tdo\n-\t\tgenerate_email $oldrev $newrev $refname | send_mail\n+\t\tgenerate_email $oldrev $newrev $refname $maxlines | send_mail\n \tdone\n fi\n-- \n1.7.1.1\n"}]}