Skip to content

Commit 6564828

Browse files
David Browngitster
authored andcommitted
git-send-email: Generalize auto-cc recipient mechanism.
There are a few options to git-send-email to suppress the automatic generation of 'Cc' fields: --suppress-from, and --signed-off-cc. However, there are other times that git-send-email automatically includes Cc'd recipients. This is not desirable for all development environments. Add a new option --suppress-cc, which can be specified one or more times to list the categories of auto-cc fields that should be suppressed. If not specified, it defaults to values to give the same behavior as specified by --suppress-from, and --signed-off-cc. The categories are: self - patch sender. Same as --suppress-from. author - patch author. cc - cc lines mentioned in the patch. cccmd - avoid running the cccmd. sob - signed off by lines. all - all non-explicit recipients Signed-off-by: David Brown <git@davidb.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7a2078b commit 6564828

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

Documentation/git-send-email.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ The --cc option must be repeated for each user you want on the cc list.
117117
Default is the value of 'sendemail.suppressfrom' configuration value;
118118
if that is unspecified, default to --no-suppress-from.
119119

120+
--suppress-cc::
121+
Specify an additional category of recipients to suppress the
122+
auto-cc of. 'self' will avoid including the sender, 'author' will
123+
avoid including the patch author, 'cc' will avoid including anyone
124+
mentioned in Cc lines in the patch, 'sob' will avoid including
125+
anyone mentioned in Signed-off-by lines, and 'cccmd' will avoid
126+
running the --cc-cmd. 'all' will suppress all auto cc values.
127+
Default is the value of 'sendemail.suppresscc' configuration value;
128+
if that is unspecified, default to 'self' if --suppress-from is
129+
specified, as well as 'sob' if --no-signed-off-cc is specified.
130+
120131
--thread, --no-thread::
121132
If this is set, the In-Reply-To header will be set on each email sent.
122133
If disabled with "--no-thread", no emails will have the In-Reply-To

git-send-email.perl

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ sub usage {
8888
8989
--smtp-ssl If set, connects to the SMTP server using SSL.
9090
91+
--suppress-cc Suppress the specified category of auto-CC. The category
92+
can be one of 'author' for the patch author, 'self' to
93+
avoid copying yourself, 'sob' for Signed-off-by lines,
94+
'cccmd' for the output of the cccmd, or 'all' to suppress
95+
all of these.
96+
9197
--suppress-from Suppress sending emails to yourself. Defaults to off.
9298
9399
--thread Specify that the "In-Reply-To:" header should be set on all
@@ -180,12 +186,13 @@ sub format_2822_time {
180186
my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
181187
my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
182188
my ($no_validate);
189+
my (@suppress_cc);
183190

184191
my %config_bool_settings = (
185192
"thread" => [\$thread, 1],
186193
"chainreplyto" => [\$chain_reply_to, 1],
187-
"suppressfrom" => [\$suppress_from, 0],
188-
"signedoffcc" => [\$signed_off_cc, 1],
194+
"suppressfrom" => [\$suppress_from, undef],
195+
"signedoffcc" => [\$signed_off_cc, undef],
189196
"smtpssl" => [\$smtp_ssl, 0],
190197
);
191198

@@ -199,6 +206,7 @@ sub format_2822_time {
199206
"aliasfiletype" => \$aliasfiletype,
200207
"bcc" => \@bcclist,
201208
"aliasesfile" => \@alias_files,
209+
"suppresscc" => \@suppress_cc,
202210
);
203211

204212
# Begin by accumulating all the variables (defined above), that we will end up
@@ -221,6 +229,7 @@ sub format_2822_time {
221229
"quiet" => \$quiet,
222230
"cc-cmd=s" => \$cc_cmd,
223231
"suppress-from!" => \$suppress_from,
232+
"suppress-cc=s" => \@suppress_cc,
224233
"signed-off-cc|signed-off-by-cc!" => \$signed_off_cc,
225234
"dry-run" => \$dry_run,
226235
"envelope-sender=s" => \$envelope_sender,
@@ -266,6 +275,35 @@ sub read_config {
266275
${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]}));
267276
}
268277

278+
# Set CC suppressions
279+
my(%suppress_cc);
280+
if (@suppress_cc) {
281+
foreach my $entry (@suppress_cc) {
282+
die "Unknown --suppress-cc field: '$entry'\n"
283+
unless $entry =~ /^(all|cccmd|cc|author|self|sob)$/;
284+
$suppress_cc{$entry} = 1;
285+
}
286+
}
287+
288+
if ($suppress_cc{'all'}) {
289+
foreach my $entry (qw (ccmd cc author self sob)) {
290+
$suppress_cc{$entry} = 1;
291+
}
292+
delete $suppress_cc{'all'};
293+
}
294+
295+
# If explicit old-style ones are specified, they trump --suppress-cc.
296+
$suppress_cc{'self'} = $suppress_from if defined $suppress_from;
297+
$suppress_cc{'sob'} = $signed_off_cc if defined $signed_off_cc;
298+
299+
# Debugging, print out the suppressions.
300+
if (0) {
301+
print "suppressions:\n";
302+
foreach my $entry (keys %suppress_cc) {
303+
printf " %-5s -> $suppress_cc{$entry}\n", $entry;
304+
}
305+
}
306+
269307
my ($repoauthor) = $repo->ident_person('author');
270308
my ($repocommitter) = $repo->ident_person('committer');
271309

@@ -711,11 +749,14 @@ sub send_message
711749

712750
} elsif (/^(Cc|From):\s+(.*)$/) {
713751
if (unquote_rfc2047($2) eq $sender) {
714-
next if ($suppress_from);
752+
next if ($suppress_cc{'self'});
715753
}
716754
elsif ($1 eq 'From') {
717755
($author, $author_encoding)
718756
= unquote_rfc2047($2);
757+
next if ($suppress_cc{'author'});
758+
} else {
759+
next if ($suppress_cc{'cc'});
719760
}
720761
printf("(mbox) Adding cc: %s from line '%s'\n",
721762
$2, $_) unless $quiet;
@@ -742,7 +783,7 @@ sub send_message
742783
# line 2 = subject
743784
# So let's support that, too.
744785
$input_format = 'lots';
745-
if (@cc == 0) {
786+
if (@cc == 0 && !$suppress_cc{'cc'}) {
746787
printf("(non-mbox) Adding cc: %s from line '%s'\n",
747788
$_, $_) unless $quiet;
748789

@@ -759,10 +800,11 @@ sub send_message
759800
}
760801
} else {
761802
$message .= $_;
762-
if (/^(Signed-off-by|Cc): (.*)$/i && $signed_off_cc) {
803+
if (/^(Signed-off-by|Cc): (.*)$/i) {
804+
next if ($suppress_cc{'sob'});
763805
my $c = $2;
764806
chomp $c;
765-
next if ($c eq $sender and $suppress_from);
807+
next if ($c eq $sender and $suppress_cc{'self'});
766808
push @cc, $c;
767809
printf("(sob) Adding cc: %s from line '%s'\n",
768810
$c, $_) unless $quiet;
@@ -771,7 +813,7 @@ sub send_message
771813
}
772814
close F;
773815

774-
if (defined $cc_cmd) {
816+
if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
775817
open(F, "$cc_cmd $t |")
776818
or die "(cc-cmd) Could not execute '$cc_cmd'";
777819
while(<F>) {

0 commit comments

Comments
 (0)