{"thread":{"id":"22280","subject":"[PATCH] post-receive-email: allow customizing of subject/intro/footer","startedAt":"2010-01-19T05:12:11Z","lastAt":"2010-01-21T20:09:51Z","messageCount":5,"participants":["Mike Frysinger","Marc Branchaud","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"132071","messageId":"1263877931-26047-1-git-send-email-vapier@gentoo.org","threadId":"22280","inReplyTo":null,"subject":"[PATCH] post-receive-email: allow customizing of subject/intro/footer","fromName":"Mike Frysinger","fromEmail":"vapier@gentoo.org","sentAt":"2010-01-19T05:12:11Z","receivedAt":"2010-01-19T05:12:11Z","isPatch":true,"sender":{"key":"vapier@gentoo.org","avatar":"https://gravatar.com/avatar/e84e90ef943ceda7d1138ced7f3cc3f866dc1fdf9cb76313ffba167fb73fa057?d=mp&s=160"},"body":"The format of the subject/intro/footer are noise imo, but rather than\ndebate the issue, let the user customize the output using the existing\ngit config hooks section.  The default output is retained for each part.\n\nSigned-off-by: Mike Frysinger <vapier@gentoo.org>\n---\n contrib/hooks/post-receive-email |   76 +++++++++++++++++++++++++++++---------\n 1 files changed, 58 insertions(+), 18 deletions(-)\n\ndiff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\nindex 58a35c8..79ab6b1 100755\n--- a/contrib/hooks/post-receive-email\n+++ b/contrib/hooks/post-receive-email\n@@ -38,6 +38,15 @@\n # hooks.emailprefix\n #   All emails have their subjects prefixed with this prefix, or \"[SCM]\"\n #   if emailprefix is unset, to aid filtering\n+# hooks.emailsubject\n+#   Allow customizing of the subject.  Default is a description of what\n+#   ref changed and how/why.\n+# hooks.emailbodyintro\n+#   Allow customizing of the body intro.  Default is friendly paragraph that\n+#   explains why the user is receiving this e-mail and what has changed.\n+# hooks.emailfooter\n+#   Allow customizing of the footer.  Default is name of the script and the\n+#   repo description.\n # hooks.showrev\n #   The shell command used to format each revision in the email, with\n #   \"%s\" replaced with the commit id.  Defaults to \"git rev-list -1\n@@ -55,6 +64,10 @@\n # \"X-Git-Newrev\", and \"X-Git-Reftype\" to enable fine tuned filtering and\n # give information for debugging.\n #\n+# All variables that start with 'email' have substitution performed on them.\n+# Patterns like @foo@ are replaced with the contents of the variable foo.\n+# See subst_vars() for the specific keywords available for substitution.\n+#\n \n # ---------------------------- Functions\n \n@@ -190,36 +203,47 @@ generate_email()\n \tgenerate_email_footer\n }\n \n+subst_vars()\n+{\n+\tsep=$(printf '\\001')\n+\t# let this be used in a pipeline or by itself\n+\t( [ \"$#\" -ne 0 ] && echo \"$@\" || cat ) | sed \\\n+\t\t-e \"s${sep}@change_type@${sep}${change_type}${sep}g\" \\\n+\t\t-e \"s${sep}@describe@${sep}${describe}${sep}g\" \\\n+\t\t-e \"s${sep}@newrev@${sep}${newrev}${sep}g\" \\\n+\t\t-e \"s${sep}@oldrev@${sep}${oldrev}${sep}g\" \\\n+\t\t-e \"s${sep}@projectdesc@${sep}${projectdesc}${sep}g\" \\\n+\t\t-e \"s${sep}@refname@${sep}${refname}${sep}g\" \\\n+\t\t-e \"s${sep}@refname_type@${sep}${refname_type}${sep}g\" \\\n+\t\t-e \"s${sep}@oldrev@${sep}${oldrev}${sep}g\" \\\n+\t\t-e \"s${sep}@short_refname@${sep}${short_refname}${sep}g\"\n+}\n+\n generate_email_header()\n {\n \t# --- Email (all stdout will be the email)\n \t# Generate header\n+\t(\n \tcat <<-EOF\n \tTo: $recipients\n-\tSubject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe\n-\tX-Git-Refname: $refname\n-\tX-Git-Reftype: $refname_type\n-\tX-Git-Oldrev: $oldrev\n-\tX-Git-Newrev: $newrev\n+\tSubject: ${emailprefix}${emailsubject}\n+\tX-Git-Refname: @refname@\n+\tX-Git-Reftype: @refname_type@\n+\tX-Git-Oldrev: @oldrev@\n+\tX-Git-Newrev: @newrev@\n+\tEOF\n \n-\tThis is an automated email from the git hooks/post-receive script. It was\n-\tgenerated because a ref change was pushed to the repository containing\n-\tthe project \"$projectdesc\".\n+\tif [ -n \"${emailbodyintro}\" ] ; then\n+\t\tprintf '\\n%s\\n' \"${emailbodyintro}\"\n+\tfi\n \n-\tThe $refname_type, $short_refname has been ${change_type}d\n-\tEOF\n+\tprintf '\\n%s\\n' \"The @refname_type@, @short_refname@ has been @change_type@d\"\n+\t) | subst_vars\n }\n \n generate_email_footer()\n {\n-\tSPACE=\" \"\n-\tcat <<-EOF\n-\n-\n-\thooks/post-receive\n-\t--${SPACE}\n-\t$projectdesc\n-\tEOF\n+\tsubst_vars \"${emailfooter}\"\n }\n \n # --------------- Branches\n@@ -671,6 +695,22 @@ recipients=$(git config hooks.mailinglist)\n announcerecipients=$(git config hooks.announcelist)\n envelopesender=$(git config hooks.envelopesender)\n emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n+emailsubject=$(git config hooks.emailsubject || \\\n+\techo '@projectdesc@ @refname_type@, @short_refname@, @change_type@d. @describe@')\n+emailbodyintro=$(git config hooks.emailbodyintro || cat <<-EOF\n+\tThis is an automated email from the git hooks/post-receive script. It was\n+\tgenerated because a ref change was pushed to the repository containing\n+\tthe project \"@projectdesc@\".\n+\tEOF\n+)\n+emailfooter=$(git config hooks.emailfooter || SPACE=\" \" cat <<-EOF\n+\n+\n+\thooks/post-receive\n+\t--${SPACE}\n+\t@projectdesc@\n+\tEOF\n+)\n custom_showrev=$(git config hooks.showrev)\n \n # --- Main loop\n-- \n1.6.6\n"},{"id":"132315","messageId":"4B5888C2.60508@xiplink.com","threadId":"22280","inReplyTo":"1263877931-26047-1-git-send-email-vapier@gentoo.org","subject":"Re: [PATCH] post-receive-email: allow customizing of subject/intro/footer","fromName":"Marc Branchaud","fromEmail":"marcnarc@xiplink.com","sentAt":"2010-01-21T17:02:58Z","receivedAt":"2010-01-21T17:02:58Z","isPatch":true,"sender":{"key":"marcnarc@xiplink.com","avatar":"https://avatars.githubusercontent.com/u/14980203?v=4"},"body":"Thanks for this!  I've been meaning to do something similar myself.  :)\n\nA couple of thoughts struck me while looking through your patch...\n\nMike Frysinger wrote:\n> The format of the subject/intro/footer are noise imo, but rather than\n> debate the issue, let the user customize the output using the existing\n> git config hooks section.  The default output is retained for each part.\n> \n> Signed-off-by: Mike Frysinger <vapier@gentoo.org>\n> ---\n>  contrib/hooks/post-receive-email |   76 +++++++++++++++++++++++++++++---------\n>  1 files changed, 58 insertions(+), 18 deletions(-)\n> \n> diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email\n> index 58a35c8..79ab6b1 100755\n> --- a/contrib/hooks/post-receive-email\n> +++ b/contrib/hooks/post-receive-email\n> @@ -38,6 +38,15 @@\n>  # hooks.emailprefix\n>  #   All emails have their subjects prefixed with this prefix, or \"[SCM]\"\n>  #   if emailprefix is unset, to aid filtering\n> +# hooks.emailsubject\n> +#   Allow customizing of the subject.  Default is a description of what\n> +#   ref changed and how/why.\n> +# hooks.emailbodyintro\n> +#   Allow customizing of the body intro.  Default is friendly paragraph that\n> +#   explains why the user is receiving this e-mail and what has changed.\n> +# hooks.emailfooter\n> +#   Allow customizing of the footer.  Default is name of the script and the\n> +#   repo description.\n>  # hooks.showrev\n>  #   The shell command used to format each revision in the email, with\n>  #   \"%s\" replaced with the commit id.  Defaults to \"git rev-list -1\n> @@ -55,6 +64,10 @@\n>  # \"X-Git-Newrev\", and \"X-Git-Reftype\" to enable fine tuned filtering and\n>  # give information for debugging.\n>  #\n> +# All variables that start with 'email' have substitution performed on them.\n> +# Patterns like @foo@ are replaced with the contents of the variable foo.\n> +# See subst_vars() for the specific keywords available for substitution.\n> +#\n>  \n>  # ---------------------------- Functions\n>  \n> @@ -190,36 +203,47 @@ generate_email()\n>  \tgenerate_email_footer\n>  }\n>  \n> +subst_vars()\n> +{\n> +\tsep=$(printf '\\001')\n> +\t# let this be used in a pipeline or by itself\n> +\t( [ \"$#\" -ne 0 ] && echo \"$@\" || cat ) | sed \\\n> +\t\t-e \"s${sep}@change_type@${sep}${change_type}${sep}g\" \\\n> +\t\t-e \"s${sep}@describe@${sep}${describe}${sep}g\" \\\n> +\t\t-e \"s${sep}@newrev@${sep}${newrev}${sep}g\" \\\n> +\t\t-e \"s${sep}@oldrev@${sep}${oldrev}${sep}g\" \\\n> +\t\t-e \"s${sep}@projectdesc@${sep}${projectdesc}${sep}g\" \\\n> +\t\t-e \"s${sep}@refname@${sep}${refname}${sep}g\" \\\n> +\t\t-e \"s${sep}@refname_type@${sep}${refname_type}${sep}g\" \\\n> +\t\t-e \"s${sep}@oldrev@${sep}${oldrev}${sep}g\" \\\n> +\t\t-e \"s${sep}@short_refname@${sep}${short_refname}${sep}g\"\n> +}\n> +\n>  generate_email_header()\n>  {\n>  \t# --- Email (all stdout will be the email)\n>  \t# Generate header\n> +\t(\n>  \tcat <<-EOF\n>  \tTo: $recipients\n> -\tSubject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe\n> -\tX-Git-Refname: $refname\n> -\tX-Git-Reftype: $refname_type\n> -\tX-Git-Oldrev: $oldrev\n> -\tX-Git-Newrev: $newrev\n> +\tSubject: ${emailprefix}${emailsubject}\n> +\tX-Git-Refname: @refname@\n> +\tX-Git-Reftype: @refname_type@\n> +\tX-Git-Oldrev: @oldrev@\n> +\tX-Git-Newrev: @newrev@\n> +\tEOF\n>  \n> -\tThis is an automated email from the git hooks/post-receive script. It was\n> -\tgenerated because a ref change was pushed to the repository containing\n> -\tthe project \"$projectdesc\".\n> +\tif [ -n \"${emailbodyintro}\" ] ; then\n\nSince the script ensures there's always a value set for emailbodyintro, why\ncheck for it here?  None of the other uses of the new config items\n(emailsubject and emailfooter) have this kind of check.\n\n> +\t\tprintf '\\n%s\\n' \"${emailbodyintro}\"\n> +\tfi\n>  \n> -\tThe $refname_type, $short_refname has been ${change_type}d\n> -\tEOF\n> +\tprintf '\\n%s\\n' \"The @refname_type@, @short_refname@ has been @change_type@d\"\n> +\t) | subst_vars\n\nAny reason why that last printf'd line shouldn't be made part of the\nemailbodyintro?\n\nSo, overall, why not make generate_email_header() be simply:\n\ngenerate_email_header()\n{\n\t# --- Email (all stdout will be the email)\n\t# Generate header\n\tsubst_vars <<-EOF\n\tTo: $recipients\n\tSubject: ${emailprefix}${emailsubject}\n\tX-Git-Refname: @refname@\n\tX-Git-Reftype: @refname_type@\n\tX-Git-Oldrev: @oldrev@\n\tX-Git-Newrev: @newrev@\n\n\t${emailbodyintro}\n\n\tEOF\n}\n\nThis would also let you simply subst_vars() so that it needn't support piped\ninvocations, no?  (Not a very drastic simplification, but still...)\n\n\t\tM.\n\n>  }\n>  \n>  generate_email_footer()\n>  {\n> -\tSPACE=\" \"\n> -\tcat <<-EOF\n> -\n> -\n> -\thooks/post-receive\n> -\t--${SPACE}\n> -\t$projectdesc\n> -\tEOF\n> +\tsubst_vars \"${emailfooter}\"\n>  }\n>  \n>  # --------------- Branches\n> @@ -671,6 +695,22 @@ recipients=$(git config hooks.mailinglist)\n>  announcerecipients=$(git config hooks.announcelist)\n>  envelopesender=$(git config hooks.envelopesender)\n>  emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')\n> +emailsubject=$(git config hooks.emailsubject || \\\n> +\techo '@projectdesc@ @refname_type@, @short_refname@, @change_type@d. @describe@')\n> +emailbodyintro=$(git config hooks.emailbodyintro || cat <<-EOF\n> +\tThis is an automated email from the git hooks/post-receive script. It was\n> +\tgenerated because a ref change was pushed to the repository containing\n> +\tthe project \"@projectdesc@\".\n> +\tEOF\n> +)\n> +emailfooter=$(git config hooks.emailfooter || SPACE=\" \" cat <<-EOF\n> +\n> +\n> +\thooks/post-receive\n> +\t--${SPACE}\n> +\t@projectdesc@\n> +\tEOF\n> +)\n>  custom_showrev=$(git config hooks.showrev)\n>  \n>  # --- Main loop\n"},{"id":"132322","messageId":"201001211259.30704.vapier@gentoo.org","threadId":"22280","inReplyTo":"4B5888C2.60508@xiplink.com","subject":"Re: [PATCH] post-receive-email: allow customizing of subject/intro/footer","fromName":"Mike Frysinger","fromEmail":"vapier@gentoo.org","sentAt":"2010-01-21T17:59:29Z","receivedAt":"2010-01-21T17:59:29Z","isPatch":true,"sender":{"key":"vapier@gentoo.org","avatar":"https://gravatar.com/avatar/e84e90ef943ceda7d1138ced7f3cc3f866dc1fdf9cb76313ffba167fb73fa057?d=mp&s=160"},"body":"On Thursday 21 January 2010 12:02:58 Marc Branchaud wrote:\n> > +\tif [ -n \"${emailbodyintro}\" ] ; then\n> > +\t\tprintf '\\n%s\\n' \"${emailbodyintro}\"\n> > +\tfi\n> \n> Since the script ensures there's always a value set for emailbodyintro, why\n> check for it here?  None of the other uses of the new config items\n> (emailsubject and emailfooter) have this kind of check.\n\nthe other values dont have newlines added to them implicitly.  if it's empty, \ni dont want to useless newlines at the start of the e-mail.\n\n> > -\tThe $refname_type, $short_refname has been ${change_type}d\n> > -\tEOF\n> > +\tprintf '\\n%s\\n' \"The @refname_type@, @short_refname@ has been\n> > @change_type@d\" +\t) | subst_vars\n> \n> Any reason why that last printf'd line shouldn't be made part of the\n> emailbodyintro?\n\nthat could work\n\n> So, overall, why not make generate_email_header() be simply:\n> \n> generate_email_header()\n> {\n> \t# --- Email (all stdout will be the email)\n> \t# Generate header\n> \tsubst_vars <<-EOF\n> \tTo: $recipients\n> \tSubject: ${emailprefix}${emailsubject}\n> \tX-Git-Refname: @refname@\n> \tX-Git-Reftype: @refname_type@\n> \tX-Git-Oldrev: @oldrev@\n> \tX-Git-Newrev: @newrev@\n> \n> \t${emailbodyintro}\n> \n> \tEOF\n> }\n> \n> This would also let you simply subst_vars() so that it needn't support\n>  piped invocations, no?  (Not a very drastic simplification, but still...)\n\nif emailbodyintro is empty, this adds two useless newlines.  otherwise, this \nwould be fine i think.\n-mike\n"},{"id":"132324","messageId":"4B589A87.2090808@xiplink.com","threadId":"22280","inReplyTo":"201001211259.30704.vapier@gentoo.org","subject":"Re: [PATCH] post-receive-email: allow customizing of subject/intro/footer","fromName":"Marc Branchaud","fromEmail":"marcnarc@xiplink.com","sentAt":"2010-01-21T18:18:47Z","receivedAt":"2010-01-21T18:18:47Z","isPatch":true,"sender":{"key":"marcnarc@xiplink.com","avatar":"https://avatars.githubusercontent.com/u/14980203?v=4"},"body":"Mike Frysinger wrote:\n> On Thursday 21 January 2010 12:02:58 Marc Branchaud wrote:\n>> \n>> So, overall, why not make generate_email_header() be simply:\n>>\n>> generate_email_header()\n>> {\n>> \t# --- Email (all stdout will be the email)\n>> \t# Generate header\n>> \tsubst_vars <<-EOF\n>> \tTo: $recipients\n>> \tSubject: ${emailprefix}${emailsubject}\n>> \tX-Git-Refname: @refname@\n>> \tX-Git-Reftype: @refname_type@\n>> \tX-Git-Oldrev: @oldrev@\n>> \tX-Git-Newrev: @newrev@\n>>\n>> \t${emailbodyintro}\n>>\n>> \tEOF\n>> }\n>>\n>> This would also let you simply subst_vars() so that it needn't support\n>>  piped invocations, no?  (Not a very drastic simplification, but still...)\n> \n> if emailbodyintro is empty, this adds two useless newlines.  otherwise, this \n> would be fine i think.\n\nPersonally, I can live with that limitation.  I think it's unlikely that\nanyone will want to get rid of the intro entirely, though maybe that's just me.\n\nOne alternative is to remove the newline after ${emailbodyintro}, but I think\nmost users will want the newline after the intro and that it's too easy to\nforget to put it there when editing the setting.\n\nAnyway, I don't have a strong opinion on the newline question.  The main\nchange I'd like to see is including that last intro line in emailbodyintro\ninstead of hardwiring it into the code.\n\n\t\tM.\n"},{"id":"132332","messageId":"7v636vp6cw.fsf@alter.siamese.dyndns.org","threadId":"22280","inReplyTo":"201001211259.30704.vapier@gentoo.org","subject":"Re: [PATCH] post-receive-email: allow customizing of subject/intro/footer","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-21T20:09:51Z","receivedAt":"2010-01-21T20:09:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mike Frysinger <vapier@gentoo.org> writes:\n\n>> So, overall, why not make generate_email_header() be simply:\n>> \n>> generate_email_header()\n>> {\n>> \t# --- Email (all stdout will be the email)\n>> \t# Generate header\n>> \tsubst_vars <<-EOF\n>> \tTo: $recipients\n>> \tSubject: ${emailprefix}${emailsubject}\n>> \tX-Git-Refname: @refname@\n>> \tX-Git-Reftype: @refname_type@\n>> \tX-Git-Oldrev: @oldrev@\n>> \tX-Git-Newrev: @newrev@\n>> \n>> \t${emailbodyintro}\n>> \n>> \tEOF\n>> }\n>> \n>> This would also let you simply subst_vars() so that it needn't support\n>>  piped invocations, no?  (Not a very drastic simplification, but still...)\n>\n> if emailbodyintro is empty, this adds two useless newlines.  otherwise, this \n> would be fine i think.\n\nI haven't looked at the original that is being improved upon (because I am\nnot very interested in this sample script myself), but I have two comments\non the above.\n\n - You can do something like this to fix that \"empty line\" issue, no?\n\n\tLF='\n        ' ;# newline\n\tsubst_vars <<-EOF\n        ...\n\n        ${emailbodyintro:+\"$emailbodyinto$LF\"}\n\tEOF\n\n - If you are using shell variable interpolation anyway, why do you still\n   need @special_name@ interpolated with perl or sed or whatever you are\n   using in subst_vars (which I didn't look at)?  If you have $refname,\n   $refname_type and friends, can't the above become \"cat <<-EOF\"?\n"}]}