Skip to content

Commit 3531e27

Browse files
jaysoffiangitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5012699 commit 3531e27

File tree

3 files changed

+169
-36
lines changed

3 files changed

+169
-36
lines changed

Documentation/git-send-email.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,25 @@ Automating
164164

165165
--suppress-cc::
166166
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.
175186

176187
--[no-]suppress-from::
177188
If this is set, do not add the From: address to the cc: list.

git-send-email.perl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ sub usage {
6868
Automating:
6969
--identity <str> * Use the sendemail.<id> options.
7070
--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.
7473
--[no-]suppress-from * Send to self. Default off.
7574
--[no-]chain-reply-to * Chain In-Reply-To: fields. Default on.
7675
--[no-]thread * Use In-Reply-To: field. Default on.
@@ -325,13 +324,13 @@ sub read_config {
325324
if (@suppress_cc) {
326325
foreach my $entry (@suppress_cc) {
327326
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)$/;
329328
$suppress_cc{$entry} = 1;
330329
}
331330
}
332331

333332
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)) {
335334
$suppress_cc{$entry} = 1;
336335
}
337336
delete $suppress_cc{'all'};
@@ -341,6 +340,13 @@ sub read_config {
341340
$suppress_cc{'self'} = $suppress_from if defined $suppress_from;
342341
$suppress_cc{'sob'} = !$signed_off_by_cc if defined $signed_off_by_cc;
343342

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+
344350
# Debugging, print out the suppressions.
345351
if (0) {
346352
print "suppressions:\n";
@@ -1020,13 +1026,17 @@ sub send_message
10201026
while(<F>) {
10211027
$message .= $_;
10221028
if (/^(Signed-off-by|Cc): (.*)$/i) {
1023-
next if ($suppress_cc{'sob'});
10241029
chomp;
1025-
my $c = $2;
1030+
my ($what, $c) = ($1, $2);
10261031
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+
}
10281038
push @cc, $c;
1029-
printf("(sob) Adding cc: %s from line '%s'\n",
1039+
printf("(body) Adding cc: %s from line '%s'\n",
10301040
$c, $_) unless $quiet;
10311041
}
10321042
}

t/t9001-send-email.sh

Lines changed: 131 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ clean_fake_sendmail() {
3232
}
3333

3434
test_expect_success 'Extract patches' '
35-
patches=`git format-patch --cc="One <[email protected]>" [email protected] -n HEAD^1`
35+
patches=`git format-patch -s --cc="One <[email protected]>" [email protected] -n HEAD^1`
3636
'
3737

3838
test_expect_success 'Send patches' '
39-
git send-email --from="Example <[email protected]>" [email protected] --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
39+
git send-email --suppress-cc=sob --from="Example <[email protected]>" [email protected] --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
4040
'
4141

4242
cat >expected <<\EOF
@@ -74,6 +74,7 @@ EOF
7474
test_expect_success 'Show all headers' '
7575
git send-email \
7676
--dry-run \
77+
--suppress-cc=sob \
7778
--from="Example <[email protected]>" \
7879
7980
@@ -193,7 +194,7 @@ test_expect_success 'second message is patch' '
193194
grep "Subject:.*Second" msgtxt2
194195
'
195196

196-
cat >expected-show-all-headers <<\EOF
197+
cat >expected-suppress-sob <<\EOF
197198
0001-Second.patch
198199
(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>'
199200
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
@@ -213,22 +214,27 @@ X-Mailer: X-MAILER-STRING
213214
Result: OK
214215
EOF
215216

216-
test_expect_success 'sendemail.cc set' '
217-
git config sendemail.cc [email protected] &&
217+
test_suppression () {
218218
git send-email \
219219
--dry-run \
220+
--suppress-cc=$1 \
220221
--from="Example <[email protected]>" \
221222
222223
--smtp-server relay.example.com \
223224
$patches |
224225
sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
225226
-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
226227
-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 [email protected] &&
234+
test_suppression sob
229235
'
230236

231-
cat >expected-show-all-headers <<\EOF
237+
cat >expected-suppress-sob <<\EOF
232238
0001-Second.patch
233239
(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>'
234240
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
@@ -250,17 +256,123 @@ EOF
250256

251257
test_expect_success 'sendemail.cc unset' '
252258
git config --unset sendemail.cc &&
253-
git send-email \
254-
--dry-run \
255-
--from="Example <[email protected]>" \
256-
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:<[email protected]>
267+
268+
From: Example <[email protected]>
269+
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 <[email protected]> from line 'From: A <[email protected]>'
285+
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
286+
(mbox) Adding cc: [email protected] from line 'Cc: One <[email protected]>, [email protected]'
287+
Dry-OK. Log says:
288+
Server: relay.example.com
289+
MAIL FROM:<[email protected]>
290+
291+
From: Example <[email protected]>
292+
293+
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 <[email protected]> from line 'From: A <[email protected]>'
309+
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
310+
(mbox) Adding cc: [email protected] from line 'Cc: One <[email protected]>, [email protected]'
311+
Dry-OK. Log says:
312+
Server: relay.example.com
313+
MAIL FROM:<[email protected]>
314+
315+
From: Example <[email protected]>
316+
317+
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 <[email protected]> from line 'From: A <[email protected]>'
333+
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
334+
(mbox) Adding cc: [email protected] from line 'Cc: One <[email protected]>, [email protected]'
335+
(body) Adding cc: C O Mitter <[email protected]> from line 'Signed-off-by: C O Mitter <[email protected]>'
336+
Dry-OK. Log says:
337+
Server: relay.example.com
338+
MAIL FROM:<[email protected]>
339+
340+
From: Example <[email protected]>
341+
342+
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 <[email protected]> from line 'From: A <[email protected]>'
358+
(body) Adding cc: C O Mitter <[email protected]> from line 'Signed-off-by: C O Mitter <[email protected]>'
359+
Dry-OK. Log says:
360+
Server: relay.example.com
361+
MAIL FROM:<[email protected]>
362+
363+
From: Example <[email protected]>
364+
365+
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
264376
'
265377

266378
test_expect_success '--compose adds MIME for utf8 body' '

0 commit comments

Comments
 (0)