builtin-diff: \No newline at end of file.
[git.git] / git-send-email.perl
index 2977b9a..b220d11 100755 (executable)
@@ -31,10 +31,10 @@ sub cleanup_compose_files();
 my $compose_filename = ".msg.$$";
 
 # Variables we fill in automatically, or via prompting:
-my (@to,@cc,$initial_reply_to,$initial_subject,@files,$from,$compose);
+my (@to,@cc,@initial_cc,$initial_reply_to,$initial_subject,@files,$from,$compose);
 
 # Behavior modification variables
-my ($chain_reply_to, $smtp_server, $quiet) = (1, "localhost", 0);
+my ($chain_reply_to, $smtp_server, $quiet, $suppress_from, $no_signed_off_cc) = (1, "localhost", 0, 0, 0);
 
 # Example reply to:
 #$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>';
@@ -48,32 +48,40 @@ my $rc = GetOptions("from=s" => \$from,
                     "in-reply-to=s" => \$initial_reply_to,
                    "subject=s" => \$initial_subject,
                    "to=s" => \@to,
+                   "cc=s" => \@initial_cc,
                    "chain-reply-to!" => \$chain_reply_to,
                    "smtp-server=s" => \$smtp_server,
                    "compose" => \$compose,
                    "quiet" => \$quiet,
+                   "suppress-from" => \$suppress_from,
+                   "no-signed-off-cc|no-signed-off-by-cc" => \$no_signed_off_cc,
         );
 
 # Now, let's fill any that aren't set in with defaults:
 
-open(GITVAR,"-|","git-var","-l")
-       or die "Failed to open pipe from git-var: $!";
-
-my ($author,$committer);
-while(<GITVAR>) {
-       chomp;
-       my ($var,$data) = split /=/,$_,2;
-       my @fields = split /\s+/, $data;
-
-       my $ident = join(" ", @fields[0...(@fields-3)]);
+sub gitvar {
+    my ($var) = @_;
+    my $fh;
+    my $pid = open($fh, '-|');
+    die "$!" unless defined $pid;
+    if (!$pid) {
+       exec('git-var', $var) or die "$!";
+    }
+    my ($val) = <$fh>;
+    close $fh or die "$!";
+    chomp($val);
+    return $val;
+}
 
-       if ($var eq 'GIT_AUTHOR_IDENT') {
-               $author = $ident;
-       } elsif ($var eq 'GIT_COMMITTER_IDENT') {
-               $committer = $ident;
-       }
+sub gitvar_ident {
+    my ($name) = @_;
+    my $val = gitvar($name);
+    my @field = split(/\s+/, $val);
+    return join(' ', @field[0...(@field-3)]);
 }
-close(GITVAR);
+
+my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
+my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
 
 my $prompting = 0;
 if (!defined $from) {
@@ -186,7 +194,9 @@ for my $f (@ARGV) {
 }
 
 if (@files) {
-       print $_,"\n" for @files;
+       unless ($quiet) {
+               print $_,"\n" for (@files);
+       }
 } else {
        print <<EOT;
 git-send-email [options] <file | directory> [... file | directory ]
@@ -195,6 +205,9 @@ Options:
 
    --to           Specify the primary "To:" line of the email.
 
+   --cc           Specify an initial "Cc:" list for the entire series
+                  of emails.
+
    --compose      Use \$EDITOR to edit an introductory message for the
                   patch series.
 
@@ -210,9 +223,19 @@ Options:
                   email sent, rather than to the first email sent.
                   Defaults to on.
 
+   --no-signed-off-cc Suppress the automatic addition of email addresses
+                 that appear in a Signed-off-by: line, to the cc: list.
+                Note: Using this option is not recommended.
+
    --smtp-server  If set, specifies the outgoing SMTP server to use.
                   Defaults to localhost.
 
+  --suppress-from Supress sending emails to yourself if your address
+                  appears in a From: line.
+
+   --quiet     Make git-send-email less verbose.  One line per email should be
+               all that is output.
+
 Error: Please specify a file or a directory on the command line.
 EOT
        exit(1);
@@ -268,7 +291,9 @@ sub send_message
 
        sendmail(%mail) or die $Mail::Sendmail::error;
 
-       unless ($quiet) {
+       if ($quiet) {
+               printf "Sent %s\n", $subject;
+       } else {
                print "OK. Log says:\n", $Mail::Sendmail::log;
                print "\n\n"
        }
@@ -280,10 +305,10 @@ make_message_id();
 $subject = $initial_subject;
 
 foreach my $t (@files) {
-       my $F = $t;
        open(F,"<",$t) or die "can't open file $t";
 
-       @cc = ();
+       my $author_not_sender = undef;
+       @cc = @initial_cc;
        my $found_mbox = 0;
        my $header_done = 0;
        $message = "";
@@ -297,8 +322,14 @@ foreach my $t (@files) {
                                        $subject = $1;
 
                                } elsif (/^(Cc|From):\s+(.*)$/) {
+                                       if ($2 eq $from) {
+                                               next if ($suppress_from);
+                                       }
+                                       else {
+                                               $author_not_sender = $2;
+                                       }
                                        printf("(mbox) Adding cc: %s from line '%s'\n",
-                                               $2, $_);
+                                               $2, $_) unless $quiet;
                                        push @cc, $2;
                                }
 
@@ -310,7 +341,7 @@ foreach my $t (@files) {
                                # So let's support that, too.
                                if (@cc == 0) {
                                        printf("(non-mbox) Adding cc: %s from line '%s'\n",
-                                               $_, $_);
+                                               $_, $_) unless $quiet;
 
                                        push @cc, $_;
 
@@ -325,16 +356,19 @@ foreach my $t (@files) {
                        }
                } else {
                        $message .=  $_;
-                       if (/^Signed-off-by: (.*)$/i) {
+                       if (/^Signed-off-by: (.*)$/i && !$no_signed_off_cc) {
                                my $c = $1;
                                chomp $c;
                                push @cc, $c;
                                printf("(sob) Adding cc: %s from line '%s'\n",
-                                       $c, $_);
+                                       $c, $_) unless $quiet;
                        }
                }
        }
        close F;
+       if (defined $author_not_sender) {
+               $message = "From: $author_not_sender\n\n$message";
+       }
 
        $cc = join(", ", unique_email_list(@cc));