{"thread":{"id":"20703","subject":"[PATCH] post-receive-email: allow customizing of subject/intro/footer","startedAt":"2009-08-23T03:51:28Z","lastAt":"2009-08-23T03:51:28Z","messageCount":1,"participants":["Mike Frysinger"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"121545","messageId":"1250999488-10649-1-git-send-email-vapier@gentoo.org","threadId":"20703","inReplyTo":null,"subject":"[PATCH] post-receive-email: allow customizing of subject/intro/footer","fromName":"Mike Frysinger","fromEmail":"vapier@gentoo.org","sentAt":"2009-08-23T03:51:28Z","receivedAt":"2009-08-23T03:51:28Z","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 2a66063..a812143 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.4\n"}]}