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>
This commit is contained in:
Jay Soffian
2009-02-14 23:32:15 -05:00
committed by Junio C Hamano
parent 5012699d98
commit 3531e2703d
3 changed files with 169 additions and 36 deletions

View File

@ -164,14 +164,25 @@ Automating
--suppress-cc:: --suppress-cc::
Specify an additional category of recipients to suppress the Specify an additional category of recipients to suppress the
auto-cc of. 'self' will avoid including the sender, 'author' will auto-cc of:
avoid including the patch author, 'cc' will avoid including anyone +
mentioned in Cc lines in the patch, 'sob' will avoid including --
anyone mentioned in Signed-off-by lines, and 'cccmd' will avoid - 'author' will avoid including the patch author
running the --cc-cmd. 'all' will suppress all auto cc values. - 'self' will avoid including the sender
Default is the value of 'sendemail.suppresscc' configuration value; - 'cc' will avoid including anyone mentioned in Cc lines in the patch header
if that is unspecified, default to 'self' if --suppress-from is except for self (use 'self' for that).
specified, as well as 'sob' if --no-signed-off-cc is specified. - 'ccbody' will avoid including anyone mentioned in Cc lines in the
patch body (commit message) except for self (use 'self' for that).
- 'sob' will avoid including anyone mentioned in Signed-off-by lines except
for self (use 'self' for that).
- 'cccmd' will avoid running the --cc-cmd.
- 'body' is equivalent to 'sob' + 'ccbody'
- 'all' will suppress all auto cc values.
--
+
Default is the value of 'sendemail.suppresscc' configuration value; if
that is unspecified, default to 'self' if --suppress-from is
specified, as well as 'body' if --no-signed-off-cc is specified.
--[no-]suppress-from:: --[no-]suppress-from::
If this is set, do not add the From: address to the cc: list. If this is set, do not add the From: address to the cc: list.

View File

@ -68,9 +68,8 @@ git send-email [options] <file | directory | rev-list options >
Automating: Automating:
--identity <str> * Use the sendemail.<id> options. --identity <str> * Use the sendemail.<id> options.
--cc-cmd <str> * Email Cc: via `<str> \$patch_path` --cc-cmd <str> * Email Cc: via `<str> \$patch_path`
--suppress-cc <str> * author, self, sob, cccmd, all. --suppress-cc <str> * author, self, sob, cc, cccmd, body, bodycc, all.
--[no-]signed-off-by-cc * Send to Cc: and Signed-off-by: --[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on.
addresses. Default on.
--[no-]suppress-from * Send to self. Default off. --[no-]suppress-from * Send to self. Default off.
--[no-]chain-reply-to * Chain In-Reply-To: fields. Default on. --[no-]chain-reply-to * Chain In-Reply-To: fields. Default on.
--[no-]thread * Use In-Reply-To: field. Default on. --[no-]thread * Use In-Reply-To: field. Default on.
@ -325,13 +324,13 @@ my(%suppress_cc);
if (@suppress_cc) { if (@suppress_cc) {
foreach my $entry (@suppress_cc) { foreach my $entry (@suppress_cc) {
die "Unknown --suppress-cc field: '$entry'\n" die "Unknown --suppress-cc field: '$entry'\n"
unless $entry =~ /^(all|cccmd|cc|author|self|sob)$/; unless $entry =~ /^(all|cccmd|cc|author|self|sob|body|bodycc)$/;
$suppress_cc{$entry} = 1; $suppress_cc{$entry} = 1;
} }
} }
if ($suppress_cc{'all'}) { if ($suppress_cc{'all'}) {
foreach my $entry (qw (ccmd cc author self sob)) { foreach my $entry (qw (ccmd cc author self sob body bodycc)) {
$suppress_cc{$entry} = 1; $suppress_cc{$entry} = 1;
} }
delete $suppress_cc{'all'}; delete $suppress_cc{'all'};
@ -341,6 +340,13 @@ if ($suppress_cc{'all'}) {
$suppress_cc{'self'} = $suppress_from if defined $suppress_from; $suppress_cc{'self'} = $suppress_from if defined $suppress_from;
$suppress_cc{'sob'} = !$signed_off_by_cc if defined $signed_off_by_cc; $suppress_cc{'sob'} = !$signed_off_by_cc if defined $signed_off_by_cc;
if ($suppress_cc{'body'}) {
foreach my $entry (qw (sob bodycc)) {
$suppress_cc{$entry} = 1;
}
delete $suppress_cc{'body'};
}
# Debugging, print out the suppressions. # Debugging, print out the suppressions.
if (0) { if (0) {
print "suppressions:\n"; print "suppressions:\n";
@ -1020,13 +1026,17 @@ foreach my $t (@files) {
while(<F>) { while(<F>) {
$message .= $_; $message .= $_;
if (/^(Signed-off-by|Cc): (.*)$/i) { if (/^(Signed-off-by|Cc): (.*)$/i) {
next if ($suppress_cc{'sob'});
chomp; chomp;
my $c = $2; my ($what, $c) = ($1, $2);
chomp $c; chomp $c;
next if ($c eq $sender and $suppress_cc{'self'}); if ($c eq $sender) {
next if ($suppress_cc{'self'});
} else {
next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
next if $suppress_cc{'bodycc'} and $what =~ /Cc/i;
}
push @cc, $c; push @cc, $c;
printf("(sob) Adding cc: %s from line '%s'\n", printf("(body) Adding cc: %s from line '%s'\n",
$c, $_) unless $quiet; $c, $_) unless $quiet;
} }
} }

View File

@ -32,11 +32,11 @@ clean_fake_sendmail() {
} }
test_expect_success 'Extract patches' ' test_expect_success 'Extract patches' '
patches=`git format-patch --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1` patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
' '
test_expect_success 'Send patches' ' test_expect_success 'Send patches' '
git send-email --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
' '
cat >expected <<\EOF cat >expected <<\EOF
@ -74,6 +74,7 @@ EOF
test_expect_success 'Show all headers' ' test_expect_success 'Show all headers' '
git send-email \ git send-email \
--dry-run \ --dry-run \
--suppress-cc=sob \
--from="Example <from@example.com>" \ --from="Example <from@example.com>" \
--to=to@example.com \ --to=to@example.com \
--cc=cc@example.com \ --cc=cc@example.com \
@ -193,7 +194,7 @@ test_expect_success 'second message is patch' '
grep "Subject:.*Second" msgtxt2 grep "Subject:.*Second" msgtxt2
' '
cat >expected-show-all-headers <<\EOF cat >expected-suppress-sob <<\EOF
0001-Second.patch 0001-Second.patch
(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' (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
Result: OK Result: OK
EOF EOF
test_expect_success 'sendemail.cc set' ' test_suppression () {
git config sendemail.cc cc@example.com &&
git send-email \ git send-email \
--dry-run \ --dry-run \
--suppress-cc=$1 \
--from="Example <from@example.com>" \ --from="Example <from@example.com>" \
--to=to@example.com \ --to=to@example.com \
--smtp-server relay.example.com \ --smtp-server relay.example.com \
@ -224,11 +225,16 @@ test_expect_success 'sendemail.cc set' '
sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
-e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
>actual-show-all-headers && >actual-suppress-$1 &&
test_cmp expected-show-all-headers actual-show-all-headers test_cmp expected-suppress-$1 actual-suppress-$1
}
test_expect_success 'sendemail.cc set' '
git config sendemail.cc cc@example.com &&
test_suppression sob
' '
cat >expected-show-all-headers <<\EOF cat >expected-suppress-sob <<\EOF
0001-Second.patch 0001-Second.patch
(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
@ -250,17 +256,123 @@ EOF
test_expect_success 'sendemail.cc unset' ' test_expect_success 'sendemail.cc unset' '
git config --unset sendemail.cc && git config --unset sendemail.cc &&
git send-email \ test_suppression sob
--dry-run \ '
--from="Example <from@example.com>" \
--to=to@example.com \ cat >expected-suppress-all <<\EOF
--smtp-server relay.example.com \ 0001-Second.patch
$patches | Dry-OK. Log says:
sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ Server: relay.example.com
-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ MAIL FROM:<from@example.com>
-e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ RCPT TO:<to@example.com>
>actual-show-all-headers && From: Example <from@example.com>
test_cmp expected-show-all-headers actual-show-all-headers To: to@example.com
Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
Result: OK
EOF
test_expect_success '--suppress-cc=all' '
test_suppression all
'
cat >expected-suppress-body <<\EOF
0001-Second.patch
(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
Dry-OK. Log says:
Server: relay.example.com
MAIL FROM:<from@example.com>
RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
From: Example <from@example.com>
To: to@example.com
Cc: A <author@example.com>, One <one@example.com>, two@example.com
Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
Result: OK
EOF
test_expect_success '--suppress-cc=body' '
test_suppression body
'
cat >expected-suppress-sob <<\EOF
0001-Second.patch
(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
Dry-OK. Log says:
Server: relay.example.com
MAIL FROM:<from@example.com>
RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>
From: Example <from@example.com>
To: to@example.com
Cc: A <author@example.com>, One <one@example.com>, two@example.com
Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
Result: OK
EOF
test_expect_success '--suppress-cc=sob' '
test_suppression sob
'
cat >expected-suppress-bodycc <<\EOF
0001-Second.patch
(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
Dry-OK. Log says:
Server: relay.example.com
MAIL FROM:<from@example.com>
RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com>
From: Example <from@example.com>
To: to@example.com
Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com>
Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
Result: OK
EOF
test_expect_success '--suppress-cc=bodycc' '
test_suppression bodycc
'
cat >expected-suppress-cc <<\EOF
0001-Second.patch
(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
Dry-OK. Log says:
Server: relay.example.com
MAIL FROM:<from@example.com>
RCPT TO:<to@example.com>,<author@example.com>,<committer@example.com>
From: Example <from@example.com>
To: to@example.com
Cc: A <author@example.com>, C O Mitter <committer@example.com>
Subject: [PATCH 1/1] Second.
Date: DATE-STRING
Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING
Result: OK
EOF
test_expect_success '--suppress-cc=cc' '
test_suppression cc
' '
test_expect_success '--compose adds MIME for utf8 body' ' test_expect_success '--compose adds MIME for utf8 body' '