From: "Kevin P. Fleming" <kpfleming@digium.com>
To: git@vger.kernel.org
Cc: "Kevin P. Fleming" <kpfleming@digium.com>
Subject: [PATCH] post-receive-email: ensure sent messages are not empty
Date: Mon, 2 Aug 2010 15:28:47 -0500 [thread overview]
Message-ID: <1280780927-29006-1-git-send-email-kpfleming@digium.com> (raw)
Changes the logic in the script to determine whether an email message
will be sent before invoking the send_mail() function; otherwise, if
the logic determines that a message will not be sent, send_mail() will
cause an empty email to be sent.
Signed-off-by: Kevin P. Fleming <kpfleming@digium.com>
---
contrib/hooks/post-receive-email | 42 +++++++++++++++++++++++++------------
1 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 30ae63d..b595452 100755
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -66,19 +66,10 @@
# ---------------------------- Functions
#
-# Top level email generation function. This decides what type of update
-# this is and calls the appropriate body-generation routine after outputting
-# the common header
+# Function to prepare for email generation. This decides what type
+# of update this is and whether an email should even be generated.
#
-# Note this function doesn't actually generate any email output, that is
-# taken care of by the functions it calls:
-# - generate_email_header
-# - generate_create_XXXX_email
-# - generate_update_XXXX_email
-# - generate_delete_XXXX_email
-# - generate_email_footer
-#
-generate_email()
+prep_for_email()
{
# --- Arguments
oldrev=$(git rev-parse $1)
@@ -171,7 +162,28 @@ generate_email()
echo >&2 "*** for $refname update $oldrev->$newrev"
exit 0
fi
+}
+#
+# Top level email generation function. This calls the appropriate
+# body-generation routine after outputting the common header.
+#
+# Note this function doesn't actually generate any email output, that is
+# taken care of by the functions it calls:
+# - generate_email_header
+# - generate_create_XXXX_email
+# - generate_update_XXXX_email
+# - generate_delete_XXXX_email
+# - generate_email_footer
+#
+# Note also that this function cannot 'exit' from the script; when this
+# function is running (in hook script mode), the send_mail() function
+# is already executing in another process, connected via a pipe, and
+# if this function exits without, whatever has been generated to that
+# point will be sent as an email... even if nothing has been generated.
+#
+generate_email()
+{
# Email parameters
# The email subject will contain the best description of the ref
# that we can build from the parameters
@@ -687,10 +699,12 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
# Output to the terminal in command line mode - if someone wanted to
# resend an email; they could redirect the output to sendmail
# themselves
- PAGER= generate_email $2 $3 $1
+ prep_for_email $2 $3 $1
+ PAGER= generate_email
else
while read oldrev newrev refname
do
- generate_email $oldrev $newrev $refname | send_mail
+ prep_for_email $oldrev $newrev $refname
+ generate_email | send_mail
done
fi
--
1.7.2
next reply other threads:[~2010-08-02 20:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-02 20:28 Kevin P. Fleming [this message]
2010-08-02 22:00 ` [PATCH] post-receive-email: ensure sent messages are not empty Junio C Hamano
2010-08-02 22:17 ` Kevin P. Fleming
[not found] <1283886126-4005-1-git-send-email-kpfleming@digium.com>
2010-09-07 19:04 ` Kevin P. Fleming
-- strict thread matches above, loose matches on Subject: below --
2010-09-10 16:09 Kevin P. Fleming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1280780927-29006-1-git-send-email-kpfleming@digium.com \
--to=kpfleming@digium.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).