git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Optional limit for number of lines generated by script

From
Marc Branchaud <marcnarc@xiplink.com>
Date
Jul 14, 2010, 16:41 UTC
Message-ID
<4C3DE8CD.5060103@xiplink.com>
In-Reply-To
<1279055909-4340-1-git-send-email-kpfleming@digium.com>
Thanks for addressing my comments!
		M.
On 10-07-13 05:18 PM, Kevin P. Fleming wrote:
Show 79 quoted lines
> 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
Previous: Kevin P. Fleming
Message 11 of 11 in “Add support for limiting number of lines generated in messages by post-receive-email”
  1. Add support for limiting number of lines generated in messages by post-receive-emailKevin P. Fleming, Jul 8, 2010
  2. Marc BranchaudJul 12, 2010
  3. Kevin P. FlemingJul 13, 2010
  4. Ævar Arnfjörð BjarmasonJul 12, 2010
  5. Optional limit for number of lines generated by scriptKevin P. Fleming, Jul 13, 2010
  6. Andreas SchwabJul 13, 2010
  7. post-receive-email: optional message line count limitKevin P. Fleming, Jul 15, 2010
  8. Junio C HamanoJul 15, 2010
  9. Kevin P. FlemingJul 16, 2010
  10. post-receive-email: optional message line count limitKevin P. Fleming, Jul 16, 2010
  11. Marc BranchaudJul 14, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.