@matheusbsbs / matheus-bagliano / commits / 656482830d
Fork 0

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>

David Brown committed Dec 25, 2007 at 19:56 UTC 656482830ddc4a4e2af132fabb118a25190439c2
2 files changed +60 -7
Documentation/git-send-email.txt
+11
@@ -117,6 +117,17 @@ The --cc option must be repeated for each user you want on the cc list.
117 Default is the value of 'sendemail.suppressfrom' configuration value;
118 if that is unspecified, default to --no-suppress-from.
119
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 +
131 --thread, --no-thread::
132 If this is set, the In-Reply-To header will be set on each email sent.
133 If disabled with "--no-thread", no emails will have the In-Reply-To
git-send-email.perl
+49 -7
@@ -88,6 +88,12 @@ Options:
88
89 --smtp-ssl If set, connects to the SMTP server using SSL.
90
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 +
97 --suppress-from Suppress sending emails to yourself. Defaults to off.
98
99 --thread Specify that the "In-Reply-To:" header should be set on all
@@ -180,12 +186,13 @@ my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
186 my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
187 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
188 my ($no_validate);
189 +my (@suppress_cc);
190
191 my %config_bool_settings = (
192 "thread" => [\$thread, 1],
193 "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],
196 "smtpssl" => [\$smtp_ssl, 0],
197 );
198
@@ -199,6 +206,7 @@ my %config_settings = (
206 "aliasfiletype" => \$aliasfiletype,
207 "bcc" => \@bcclist,
208 "aliasesfile" => \@alias_files,
209 + "suppresscc" => \@suppress_cc,
210 );
211
212 # Begin by accumulating all the variables (defined above), that we will end up
@@ -221,6 +229,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
229 "quiet" => \$quiet,
230 "cc-cmd=s" => \$cc_cmd,
231 "suppress-from!" => \$suppress_from,
232 + "suppress-cc=s" => \@suppress_cc,
233 "signed-off-cc|signed-off-by-cc!" => \$signed_off_cc,
234 "dry-run" => \$dry_run,
235 "envelope-sender=s" => \$envelope_sender,
@@ -266,6 +275,35 @@ foreach my $setting (values %config_bool_settings) {
275 ${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]}));
276 }
277
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 +
307 my ($repoauthor) = $repo->ident_person('author');
308 my ($repocommitter) = $repo->ident_person('committer');
309
@@ -711,11 +749,14 @@ foreach my $t (@files) {
749
750 } elsif (/^(Cc|From):\s+(.*)$/) {
751 if (unquote_rfc2047($2) eq $sender) {
714 - next if ($suppress_from);
752 + next if ($suppress_cc{'self'});
753 }
754 elsif ($1 eq 'From') {
755 ($author, $author_encoding)
756 = unquote_rfc2047($2);
757 + next if ($suppress_cc{'author'});
758 + } else {
759 + next if ($suppress_cc{'cc'});
760 }
761 printf("(mbox) Adding cc: %s from line '%s'\n",
762 $2, $_) unless $quiet;
@@ -742,7 +783,7 @@ foreach my $t (@files) {
783 # line 2 = subject
784 # So let's support that, too.
785 $input_format = 'lots';
745 - if (@cc == 0) {
786 + if (@cc == 0 && !$suppress_cc{'cc'}) {
787 printf("(non-mbox) Adding cc: %s from line '%s'\n",
788 $_, $_) unless $quiet;
789
@@ -759,10 +800,11 @@ foreach my $t (@files) {
800 }
801 } else {
802 $message .= $_;
762 - if (/^(Signed-off-by|Cc): (.*)$/i && $signed_off_cc) {
803 + if (/^(Signed-off-by|Cc): (.*)$/i) {
804 + next if ($suppress_cc{'sob'});
805 my $c = $2;
806 chomp $c;
765 - next if ($c eq $sender and $suppress_from);
807 + next if ($c eq $sender and $suppress_cc{'self'});
808 push @cc, $c;
809 printf("(sob) Adding cc: %s from line '%s'\n",
810 $c, $_) unless $quiet;
@@ -771,7 +813,7 @@ foreach my $t (@files) {
813 }
814 close F;
815
774 - if (defined $cc_cmd) {
816 + if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
817 open(F, "$cc_cmd $t |")
818 or die "(cc-cmd) Could not execute '$cc_cmd'";
819 while(<F>) {