71
71
# ---------------------------- Functions
72
72
73
73
#
74
- # Top level email generation function. This decides what type of update
75
- # this is and calls the appropriate body-generation routine after outputting
76
- # the common header
74
+ # Function to prepare for email generation. This decides what type
75
+ # of update this is and whether an email should even be generated.
77
76
#
78
- # Note this function doesn't actually generate any email output, that is
79
- # taken care of by the functions it calls:
80
- # - generate_email_header
81
- # - generate_create_XXXX_email
82
- # - generate_update_XXXX_email
83
- # - generate_delete_XXXX_email
84
- # - generate_email_footer
85
- #
86
- generate_email ()
77
+ prep_for_email ()
87
78
{
88
79
# --- Arguments
89
80
oldrev=$( git rev-parse $1 )
@@ -159,7 +150,7 @@ generate_email()
159
150
# Anything else (is there anything else?)
160
151
echo >&2 " *** Unknown type of update to $refname ($rev_type )"
161
152
echo >&2 " *** - no email generated"
162
- exit 1
153
+ return 0
163
154
;;
164
155
esac
165
156
@@ -175,9 +166,32 @@ generate_email()
175
166
esac
176
167
echo >&2 " *** $config_name is not set so no email will be sent"
177
168
echo >&2 " *** for $refname update $oldrev ->$newrev "
178
- exit 0
169
+ return 0
179
170
fi
180
171
172
+ return 1
173
+ }
174
+
175
+ #
176
+ # Top level email generation function. This calls the appropriate
177
+ # body-generation routine after outputting the common header.
178
+ #
179
+ # Note this function doesn't actually generate any email output, that is
180
+ # taken care of by the functions it calls:
181
+ # - generate_email_header
182
+ # - generate_create_XXXX_email
183
+ # - generate_update_XXXX_email
184
+ # - generate_delete_XXXX_email
185
+ # - generate_email_footer
186
+ #
187
+ # Note also that this function cannot 'exit' from the script; when this
188
+ # function is running (in hook script mode), the send_mail() function
189
+ # is already executing in another process, connected via a pipe, and
190
+ # if this function exits without, whatever has been generated to that
191
+ # point will be sent as an email... even if nothing has been generated.
192
+ #
193
+ generate_email ()
194
+ {
181
195
# Email parameters
182
196
# The email subject will contain the best description of the ref
183
197
# that we can build from the parameters
@@ -717,10 +731,11 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
717
731
# Output to the terminal in command line mode - if someone wanted to
718
732
# resend an email; they could redirect the output to sendmail
719
733
# themselves
720
- PAGER= generate_email $2 $3 $1
734
+ prep_for_email $2 $3 $1 && PAGER= generate_email
721
735
else
722
736
while read oldrev newrev refname
723
737
do
724
- generate_email $oldrev $newrev $refname $maxlines | send_mail
738
+ prep_for_email $oldrev $newrev $refname || continue
739
+ generate_email $maxlines | send_mail
725
740
done
726
741
fi
0 commit comments