Re: [PATCH] git-send-email: Generalize auto-cc recipient mechanism.

Subsystems: the rest

5 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] git-send-email: Generalize auto-cc recipient mechanism.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:01

David Brown [off-list ref] writes:
...
  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 <redacted>
...
What bothers me most about this change is that --signed-of-cc
and --suppress-from are silently ignored if --suppress-cc is given, either
on the command line, or in the config.
The order in which various variables are set in the current code
before your patch is like this:

 * my ($var) introduces them -- they are undefined at the
   beginning;

 * GetOptions() may set them to explicit values;

 * read_config(), first for the specific sendemail identity and
   then for the generic ones, fill the ones that are still
   undefined;

 * the built-in default from %config_bool_settings are used to
   fill the ones that are still undefined at this point;

Now, I think you can build on top of the above by adding the
following after that sequence:

 * fill %suppress_cc with explicit @suppress_cc GetOptions and
   read_config() read;

 * if the --suppress-from and/or --signed-off-by-cc, either from
   GetOptions() or from read_config() are given, make them
   override what @suppress_cc says.  So giving --suppress-cc=all
   and --signed-off-by-cc at the same time will still send cc to
   people who signed off the patch (because these old-style ones
   are more specific).

Perhaps something like this (untested, of course!) patch on top
of yours.


 git-send-email.perl |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 1f03d12..cde5ffb 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -188,8 +188,8 @@ my (@suppress_cc);
 my %config_bool_settings = (
     "thread" => [\$thread, 1],
     "chainreplyto" => [\$chain_reply_to, 1],
-    "suppressfrom" => [\$suppress_from, 0],
-    "signedoffcc" => [\$signed_off_cc, 1],
+    "suppressfrom" => [\$suppress_from, undef],
+    "signedoffcc" => [\$signed_off_cc, undef],
     "smtpssl" => [\$smtp_ssl, 0],
 );
 
@@ -279,18 +279,20 @@ if (@suppress_cc) {
 			unless $entry =~ /^(all|cccmd|cc|author|self|sob)$/;
 		$suppress_cc{$entry} = 1;
 	}
-} else {
-	# Convert the old-style options.
-	$suppress_cc{'self'} = 1 if $suppress_from;
-	$suppress_cc{'sob'} = 1 unless $signed_off_cc;
 }
-
 if ($suppress_cc{'all'}) {
 	foreach my $entry (qw (ccmd cc author self sob)) {
 		$suppress_cc{$entry} = 1;
 	}
 	delete $suppress_cc{'all'};
 }
+# If explicit old-style ones are specified, they trump supress-cc
+if (defined $suppress_from) {
+	$suppress_cc{'self'} = $suppress_from;
+}
+if (defined $signed_off_cc) {
+	$suppress_cc{'sob'} = !$signed_off_cc;
+}
 
 my ($repoauthor) = $repo->ident_person('author');
 my ($repocommitter) = $repo->ident_person('committer');

Re: [PATCH] git-send-email: Generalize auto-cc recipient mechanism.

From: David Brown <hidden>
Date: 2016-06-15 22:44:01

On Tue, Dec 25, 2007 at 01:04:54PM -0800, Junio C Hamano wrote:
+# If explicit old-style ones are specified, they trump supress-cc
+if (defined $suppress_from) {
+	$suppress_cc{'self'} = $suppress_from;
+}
+if (defined $signed_off_cc) {
+	$suppress_cc{'sob'} = !$signed_off_cc;
+}
This changes the default behavior to --no-signed-off-cc, if nothing is
specified.  I'll see if I can add something that will set that if no
suppress-cc's are set.

Patch to follow shortly.

David

[PATCH] git-send-email: Generalize auto-cc recipient mechanism.

From: David Brown <hidden>
Date: 2016-06-15 22:44:01

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 <redacted>
---
I've now added changes similar to those suggested by Junio Hamano so
that signed-off-cc and suppress-from override values set by
signed-off-by.

Dave

 Documentation/git-send-email.txt |   11 +++++++
 git-send-email.perl              |   56 +++++++++++++++++++++++++++++++++-----
 2 files changed, 60 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index f0bd285..3dcea86 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -117,6 +117,17 @@ The --cc option must be repeated for each user you want on the cc list.
         Default is the value of 'sendemail.suppressfrom' configuration value;
         if that is unspecified, default to --no-suppress-from.
 
+--suppress-cc::
+	Specify an additional category of recipients to suppress the
+	auto-cc of.  'self' will avoid including the sender, 'author' will
+	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
+	running the --cc-cmd.  '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 'sob' if --no-signed-off-cc is specified.
+
 --thread, --no-thread::
 	If this is set, the In-Reply-To header will be set on each email sent.
 	If disabled with "--no-thread", no emails will have the In-Reply-To
diff --git a/git-send-email.perl b/git-send-email.perl
index e47994a..a4cf4a9 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -88,6 +88,12 @@ Options:
 
    --smtp-ssl     If set, connects to the SMTP server using SSL.
 
+   --suppress-cc  Suppress the specified category of auto-CC.  The category
+                  can be one of 'author' for the patch author, 'self' to
+                  avoid copying yourself, 'sob' for Signed-off-by lines,
+                  'cccmd' for the output of the cccmd, or 'all' to suppress
+                  all of these.
+
    --suppress-from Suppress sending emails to yourself. Defaults to off.
 
    --thread       Specify that the "In-Reply-To:" header should be set on all
@@ -177,12 +183,13 @@ my ($quiet, $dry_run) = (0, 0);
 my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
 my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
+my (@suppress_cc);
 
 my %config_bool_settings = (
     "thread" => [\$thread, 1],
     "chainreplyto" => [\$chain_reply_to, 1],
-    "suppressfrom" => [\$suppress_from, 0],
-    "signedoffcc" => [\$signed_off_cc, 1],
+    "suppressfrom" => [\$suppress_from, undef],
+    "signedoffcc" => [\$signed_off_cc, undef],
     "smtpssl" => [\$smtp_ssl, 0],
 );
 
@@ -196,6 +203,7 @@ my %config_settings = (
     "aliasfiletype" => \$aliasfiletype,
     "bcc" => \@bcclist,
     "aliasesfile" => \@alias_files,
+    "suppresscc" => \@suppress_cc,
 );
 
 # Begin by accumulating all the variables (defined above), that we will end up
@@ -218,6 +226,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
 		    "quiet" => \$quiet,
 		    "cc-cmd=s" => \$cc_cmd,
 		    "suppress-from!" => \$suppress_from,
+		    "suppress-cc=s" => \@suppress_cc,
 		    "signed-off-cc|signed-off-by-cc!" => \$signed_off_cc,
 		    "dry-run" => \$dry_run,
 		    "envelope-sender=s" => \$envelope_sender,
@@ -262,6 +271,35 @@ foreach my $setting (values %config_bool_settings) {
 	${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]}));
 }
 
+# Set CC suppressions
+my(%suppress_cc);
+if (@suppress_cc) {
+	foreach my $entry (@suppress_cc) {
+		die "Unknown --suppress-cc field: '$entry'\n"
+			unless $entry =~ /^(all|cccmd|cc|author|self|sob)$/;
+		$suppress_cc{$entry} = 1;
+	}
+}
+
+if ($suppress_cc{'all'}) {
+	foreach my $entry (qw (ccmd cc author self sob)) {
+		$suppress_cc{$entry} = 1;
+	}
+	delete $suppress_cc{'all'};
+}
+
+# If explicit old-style ones are specified, they trump --suppress-cc.
+$suppress_cc{'self'} = $suppress_from if defined $suppress_from;
+$suppress_cc{'sob'} = $signed_off_cc if defined $signed_off_cc;
+
+# Debugging, print out the suppressions.
+if (0) {
+	print "suppressions:\n";
+	foreach my $entry (keys %suppress_cc) {
+		printf "  %-5s -> $suppress_cc{$entry}\n", $entry;
+	}
+}
+
 my ($repoauthor) = $repo->ident_person('author');
 my ($repocommitter) = $repo->ident_person('committer');
 
@@ -701,11 +739,14 @@ foreach my $t (@files) {
 
 				} elsif (/^(Cc|From):\s+(.*)$/) {
 					if (unquote_rfc2047($2) eq $sender) {
-						next if ($suppress_from);
+						next if ($suppress_cc{'self'});
 					}
 					elsif ($1 eq 'From') {
 						($author, $author_encoding)
 						  = unquote_rfc2047($2);
+						next if ($suppress_cc{'author'});
+					} else {
+						next if ($suppress_cc{'cc'});
 					}
 					printf("(mbox) Adding cc: %s from line '%s'\n",
 						$2, $_) unless $quiet;
@@ -732,7 +773,7 @@ foreach my $t (@files) {
 				# line 2 = subject
 				# So let's support that, too.
 				$input_format = 'lots';
-				if (@cc == 0) {
+				if (@cc == 0 && !$suppress_cc{'cc'}) {
 					printf("(non-mbox) Adding cc: %s from line '%s'\n",
 						$_, $_) unless $quiet;
 
@@ -749,10 +790,11 @@ foreach my $t (@files) {
 			}
 		} else {
 			$message .=  $_;
-			if (/^(Signed-off-by|Cc): (.*)$/i && $signed_off_cc) {
+			if (/^(Signed-off-by|Cc): (.*)$/i) {
+				next if ($suppress_cc{'sob'});
 				my $c = $2;
 				chomp $c;
-				next if ($c eq $sender and $suppress_from);
+				next if ($c eq $sender and $suppress_cc{'self'});
 				push @cc, $c;
 				printf("(sob) Adding cc: %s from line '%s'\n",
 					$c, $_) unless $quiet;
@@ -761,7 +803,7 @@ foreach my $t (@files) {
 	}
 	close F;
 
-	if (defined $cc_cmd) {
+	if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
 		open(F, "$cc_cmd $t |")
 			or die "(cc-cmd) Could not execute '$cc_cmd'";
 		while(<F>) {
-- 
1.5.3.7

Re: [PATCH] git-send-email: Generalize auto-cc recipient mechanism.

From: Sean <hidden>
Date: 2016-06-15 22:44:01

On Tue, 25 Dec 2007 19:56:29 -0800
David Brown [off-list ref] wrote:
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
Hi Dave,

It's great to see you're taking care of this issue, it's one that i've tripped over
a few times.  If your patch is accepted as-is, i think it's an improvement.

But i wonder about the case where a user has "sendemail.suppresscc = all" in their
~/.gitconfig.   For the occasion when they do want to cc the author of
a patch, what do they do?  The above UI seems to lack a way to enable a cc option
that has been disabled by default.

Cheers,
Sean

Re: [PATCH] git-send-email: Generalize auto-cc recipient mechanism.

From: David Brown <hidden>
Date: 2016-06-15 22:44:01

On Tue, Dec 25, 2007 at 11:54:38PM -0500, Sean wrote:
But i wonder about the case where a user has "sendemail.suppresscc = all" in their
~/.gitconfig.   For the occasion when they do want to cc the author of
a patch, what do they do?  The above UI seems to lack a way to enable a cc option
that has been disabled by default.
Well, in that instance, --no-suppress-from would override that, if I did it
right.  Perhaps we could add an unsuppress-cc option, but then the whole
thing is starting to get more complicated than I think it really needs to
be.

My suggestion would be to keep this patch as is, and if the people using it
decide they want the override option, we/I can figure out how to add it.

Dave
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help