@matheusbsbs / matheus-bagliano / commits / 3531e2703d
Fork 0

send-email: --suppress-cc improvements

Since 6564828 (git-send-email: Generalize auto-cc recipient mechanism., 2007-12-25) we can suppress automatic Cc generation separately for each of the possible address sources. However, --suppress-cc=sob suppressed both SOB lines and body (but not header) Cc lines, contrary to the name. Change --suppress-cc=sob to mean only SOB lines, and add separate choices 'bodycc' (body Cc lines) and 'body' (both 'sob' and 'bodycc'). The option --no-signed-off-by-cc now acts like --suppress-cc=sob, which is not backwards compatible but matches the name of the option. Also update the documentation and add a few tests. Original patch by me. Revised by Thomas Rast, who contributed the documentation and test updates. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jay Soffian committed Feb 14, 2009 at 23:32 UTC 3531e2703d8e441bfb4a6765459317b3db3f224c
3 files changed +169 -36
Documentation/git-send-email.txt
+19 -8
@@ -164,14 +164,25 @@ Automating
164
165 --suppress-cc::
166 Specify an additional category of recipients to suppress the
167 - auto-cc of. 'self' will avoid including the sender, 'author' will
168 - avoid including the patch author, 'cc' will avoid including anyone
169 - mentioned in Cc lines in the patch, 'sob' will avoid including
170 - anyone mentioned in Signed-off-by lines, and 'cccmd' will avoid
171 - running the --cc-cmd. 'all' will suppress all auto cc values.
172 - Default is the value of 'sendemail.suppresscc' configuration value;
173 - if that is unspecified, default to 'self' if --suppress-from is
174 - specified, as well as 'sob' if --no-signed-off-cc is specified.
167 + auto-cc of:
168 ++
169 +--
170 +- 'author' will avoid including the patch author
171 +- 'self' will avoid including the sender
172 +- 'cc' will avoid including anyone mentioned in Cc lines in the patch header
173 + except for self (use 'self' for that).
174 +- 'ccbody' will avoid including anyone mentioned in Cc lines in the
175 + patch body (commit message) except for self (use 'self' for that).
176 +- 'sob' will avoid including anyone mentioned in Signed-off-by lines except
177 + for self (use 'self' for that).
178 +- 'cccmd' will avoid running the --cc-cmd.
179 +- 'body' is equivalent to 'sob' + 'ccbody'
180 +- 'all' will suppress all auto cc values.
181 +--
182 ++
183 +Default is the value of 'sendemail.suppresscc' configuration value; if
184 +that is unspecified, default to 'self' if --suppress-from is
185 +specified, as well as 'body' if --no-signed-off-cc is specified.
186
187 --[no-]suppress-from::
188 If this is set, do not add the From: address to the cc: list.
git-send-email.perl
+19 -9
@@ -68,9 +68,8 @@ git send-email [options] <file | directory | rev-list options >
68 Automating:
69 --identity <str> * Use the sendemail.<id> options.
70 --cc-cmd <str> * Email Cc: via `<str> \$patch_path`
71 - --suppress-cc <str> * author, self, sob, cccmd, all.
72 - --[no-]signed-off-by-cc * Send to Cc: and Signed-off-by:
73 - addresses. Default on.
71 + --suppress-cc <str> * author, self, sob, cc, cccmd, body, bodycc, all.
72 + --[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on.
73 --[no-]suppress-from * Send to self. Default off.
74 --[no-]chain-reply-to * Chain In-Reply-To: fields. Default on.
75 --[no-]thread * Use In-Reply-To: field. Default on.
@@ -325,13 +324,13 @@ my(%suppress_cc);
324 if (@suppress_cc) {
325 foreach my $entry (@suppress_cc) {
326 die "Unknown --suppress-cc field: '$entry'\n"
328 - unless $entry =~ /^(all|cccmd|cc|author|self|sob)$/;
327 + unless $entry =~ /^(all|cccmd|cc|author|self|sob|body|bodycc)$/;
328 $suppress_cc{$entry} = 1;
329 }
330 }
331
332 if ($suppress_cc{'all'}) {
334 - foreach my $entry (qw (ccmd cc author self sob)) {
333 + foreach my $entry (qw (ccmd cc author self sob body bodycc)) {
334 $suppress_cc{$entry} = 1;
335 }
336 delete $suppress_cc{'all'};
@@ -341,6 +340,13 @@ if ($suppress_cc{'all'}) {
340 $suppress_cc{'self'} = $suppress_from if defined $suppress_from;
341 $suppress_cc{'sob'} = !$signed_off_by_cc if defined $signed_off_by_cc;
342
343 +if ($suppress_cc{'body'}) {
344 + foreach my $entry (qw (sob bodycc)) {
345 + $suppress_cc{$entry} = 1;
346 + }
347 + delete $suppress_cc{'body'};
348 +}
349 +
350 # Debugging, print out the suppressions.
351 if (0) {
352 print "suppressions:\n";
@@ -1020,13 +1026,17 @@ foreach my $t (@files) {
1026 while(<F>) {
1027 $message .= $_;
1028 if (/^(Signed-off-by|Cc): (.*)$/i) {
1023 - next if ($suppress_cc{'sob'});
1029 chomp;
1025 - my $c = $2;
1030 + my ($what, $c) = ($1, $2);
1031 chomp $c;
1027 - next if ($c eq $sender and $suppress_cc{'self'});
1032 + if ($c eq $sender) {
1033 + next if ($suppress_cc{'self'});
1034 + } else {
1035 + next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
1036 + next if $suppress_cc{'bodycc'} and $what =~ /Cc/i;
1037 + }
1038 push @cc, $c;
1029 - printf("(sob) Adding cc: %s from line '%s'\n",
1039 + printf("(body) Adding cc: %s from line '%s'\n",
1040 $c, $_) unless $quiet;
1041 }
1042 }
t/t9001-send-email.sh
+131 -19
@@ -32,11 +32,11 @@ clean_fake_sendmail() {
32 }
33
34 test_expect_success 'Extract patches' '
35 - patches=`git format-patch --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
35 + patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
36 '
37
38 test_expect_success 'Send patches' '
39 - git send-email --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
39 + git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
40 '
41
42 cat >expected <<\EOF
@@ -74,6 +74,7 @@ EOF
74 test_expect_success 'Show all headers' '
75 git send-email \
76 --dry-run \
77 + --suppress-cc=sob \
78 --from="Example <from@example.com>" \
79 --to=to@example.com \
80 --cc=cc@example.com \
@@ -193,7 +194,7 @@ test_expect_success 'second message is patch' '
194 grep "Subject:.*Second" msgtxt2
195 '
196
196 -cat >expected-show-all-headers <<\EOF
197 +cat >expected-suppress-sob <<\EOF
198 0001-Second.patch
199 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
200 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
@@ -213,10 +214,10 @@ X-Mailer: X-MAILER-STRING
214 Result: OK
215 EOF
216
216 -test_expect_success 'sendemail.cc set' '
217 - git config sendemail.cc cc@example.com &&
217 +test_suppression () {
218 git send-email \
219 --dry-run \
220 + --suppress-cc=$1 \
221 --from="Example <from@example.com>" \
222 --to=to@example.com \
223 --smtp-server relay.example.com \
@@ -224,11 +225,16 @@ test_expect_success 'sendemail.cc set' '
225 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
226 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
227 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
227 - >actual-show-all-headers &&
228 - test_cmp expected-show-all-headers actual-show-all-headers
228 + >actual-suppress-$1 &&
229 + test_cmp expected-suppress-$1 actual-suppress-$1
230 +}
231 +
232 +test_expect_success 'sendemail.cc set' '
233 + git config sendemail.cc cc@example.com &&
234 + test_suppression sob
235 '
236
231 -cat >expected-show-all-headers <<\EOF
237 +cat >expected-suppress-sob <<\EOF
238 0001-Second.patch
239 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
240 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
@@ -250,17 +256,123 @@ EOF
256
257 test_expect_success 'sendemail.cc unset' '
258 git config --unset sendemail.cc &&
253 - git send-email \
254 - --dry-run \
255 - --from="Example <from@example.com>" \
256 - --to=to@example.com \
257 - --smtp-server relay.example.com \
258 - $patches |
259 - sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
260 - -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
261 - -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
262 - >actual-show-all-headers &&
263 - test_cmp expected-show-all-headers actual-show-all-headers
259 + test_suppression sob
260 +'
261 +
262 +cat >expected-suppress-all <<\EOF
263 +0001-Second.patch
264 +Dry-OK. Log says:
265 +Server: relay.example.com
266 +MAIL FROM:<from@example.com>
267 +RCPT TO:<to@example.com>
268 +From: Example <from@example.com>
269 +To: to@example.com
270 +Subject: [PATCH 1/1] Second.
271 +Date: DATE-STRING
272 +Message-Id: MESSAGE-ID-STRING
273 +X-Mailer: X-MAILER-STRING
274 +
275 +Result: OK
276 +EOF
277 +
278 +test_expect_success '--suppress-cc=all' '
279 + test_suppression all
280 +'
281 +
282 +cat >expected-suppress-body <<\EOF
283 +0001-Second.patch
284 +(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
285 +(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
286 +(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
287 +Dry-OK. Log says:
288 +Server: relay.example.com
289 +MAIL FROM:<from@example.com>
290 +RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
291 +From: Example <from@example.com>
292 +To: to@example.com
293 +Cc: A <author@example.com>, One <one@example.com>, two@example.com
294 +Subject: [PATCH 1/1] Second.
295 +Date: DATE-STRING
296 +Message-Id: MESSAGE-ID-STRING
297 +X-Mailer: X-MAILER-STRING
298 +
299 +Result: OK
300 +EOF
301 +
302 +test_expect_success '--suppress-cc=body' '
303 + test_suppression body
304 +'
305 +
306 +cat >expected-suppress-sob <<\EOF
307 +0001-Second.patch
308 +(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
309 +(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
310 +(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
311 +Dry-OK. Log says:
312 +Server: relay.example.com
313 +MAIL FROM:<from@example.com>
314 +RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
315 +From: Example <from@example.com>
316 +To: to@example.com
317 +Cc: A <author@example.com>, One <one@example.com>, two@example.com
318 +Subject: [PATCH 1/1] Second.
319 +Date: DATE-STRING
320 +Message-Id: MESSAGE-ID-STRING
321 +X-Mailer: X-MAILER-STRING
322 +
323 +Result: OK
324 +EOF
325 +
326 +test_expect_success '--suppress-cc=sob' '
327 + test_suppression sob
328 +'
329 +
330 +cat >expected-suppress-bodycc <<\EOF
331 +0001-Second.patch
332 +(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
333 +(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
334 +(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
335 +(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
336 +Dry-OK. Log says:
337 +Server: relay.example.com
338 +MAIL FROM:<from@example.com>
339 +RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
340 +From: Example <from@example.com>
341 +To: to@example.com
342 +Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
343 +Subject: [PATCH 1/1] Second.
344 +Date: DATE-STRING
345 +Message-Id: MESSAGE-ID-STRING
346 +X-Mailer: X-MAILER-STRING
347 +
348 +Result: OK
349 +EOF
350 +
351 +test_expect_success '--suppress-cc=bodycc' '
352 + test_suppression bodycc
353 +'
354 +
355 +cat >expected-suppress-cc <<\EOF
356 +0001-Second.patch
357 +(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
358 +(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
359 +Dry-OK. Log says:
360 +Server: relay.example.com
361 +MAIL FROM:<from@example.com>
362 +RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com>
363 +From: Example <from@example.com>
364 +To: to@example.com
365 +Cc: A <author@example.com>, C O Mitter <committer@example.com>
366 +Subject: [PATCH 1/1] Second.
367 +Date: DATE-STRING
368 +Message-Id: MESSAGE-ID-STRING
369 +X-Mailer: X-MAILER-STRING
370 +
371 +Result: OK
372 +EOF
373 +
374 +test_expect_success '--suppress-cc=cc' '
375 + test_suppression cc
376 '
377
378 test_expect_success '--compose adds MIME for utf8 body' '