aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-10-26 21:52:26 -0700
committerJunio C Hamano <gitster@pobox.com>2010-10-26 21:52:26 -0700
commit9b1054d93e7e8564d0d9865cb7118cb6e756c74b (patch)
tree0b9de3569b26589e6fa265e15d1ed204828ce069
parente6202dfe0021e2662eb4e19e6d01e33081608b5e (diff)
parent6e74e075d25aea67cf973e456a6804c0c3741235 (diff)
downloadgit-9b1054d93e7e8564d0d9865cb7118cb6e756c74b.tar.gz
git-9b1054d93e7e8564d0d9865cb7118cb6e756c74b.tar.xz
Merge branch 'jp/send-email-to-cmd'
* jp/send-email-to-cmd: git-send-email.perl: Add --to-cmd Conflicts: git-send-email.perl
-rw-r--r--Documentation/git-send-email.txt8
-rwxr-xr-xgit-send-email.perl51
-rwxr-xr-xt/t9001-send-email.sh18
3 files changed, 59 insertions, 18 deletions
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index cde404a46..05904e0e7 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -97,7 +97,7 @@ See the CONFIGURATION section for 'sendemail.multiedit'.
Specify the primary recipient of the emails generated. Generally, this
will be the upstream maintainer of the project involved. Default is the
value of the 'sendemail.to' configuration value; if that is unspecified,
- this will be prompted for.
+ and --to-cmd is not specified, this will be prompted for.
+
The --to option must be repeated for each user you want on the to list.
@@ -186,6 +186,12 @@ must be used for each option.
Automating
~~~~~~~~~~
+--to-cmd=<command>::
+ Specify a command to execute once per patch file which
+ should generate patch file specific "To:" entries.
+ Output of this command must be single email address per line.
+ Default is the value of 'sendemail.tocmd' configuration value.
+
--cc-cmd=<command>::
Specify a command to execute once per patch file which
should generate patch file specific "Cc:" entries.
diff --git a/git-send-email.perl b/git-send-email.perl
index 458e86afd..897bf5960 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -72,6 +72,7 @@ git send-email [options] <file | directory | rev-list options >
Automating:
--identity <str> * Use the sendemail.<id> options.
+ --to-cmd <str> * Email To: via `<str> \$patch_path`
--cc-cmd <str> * Email Cc: via `<str> \$patch_path`
--suppress-cc <str> * author, self, sob, cc, cccmd, body, bodycc, all.
--[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on.
@@ -191,7 +192,8 @@ sub do_edit {
}
# Variables with corresponding config settings
-my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
+my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);
+my ($to_cmd, $cc_cmd);
my ($smtp_server, $smtp_server_port, @smtp_server_options);
my ($smtp_authuser, $smtp_encryption);
my ($identity, $aliasfiletype, @alias_files, $smtp_domain);
@@ -220,6 +222,7 @@ my %config_settings = (
"smtppass" => \$smtp_authpass,
"smtpdomain" => \$smtp_domain,
"to" => \@to,
+ "tocmd" => \$to_cmd,
"cc" => \@initial_cc,
"cccmd" => \$cc_cmd,
"aliasfiletype" => \$aliasfiletype,
@@ -278,6 +281,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
"in-reply-to=s" => \$initial_reply_to,
"subject=s" => \$initial_subject,
"to=s" => \@to,
+ "to-cmd=s" => \$to_cmd,
"no-to" => \$no_to,
"cc=s" => \@initial_cc,
"no-cc" => \$no_cc,
@@ -729,7 +733,7 @@ if (!defined $sender) {
$prompting++;
}
-if (!@to) {
+if (!@to && !defined $to_cmd) {
my $to = ask("Who should the emails be sent to? ");
push @to, parse_address_line($to) if defined $to; # sanitized/validated later
$prompting++;
@@ -1258,21 +1262,10 @@ foreach my $t (@files) {
}
close F;
- if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
- open(F, "$cc_cmd \Q$t\E |")
- or die "(cc-cmd) Could not execute '$cc_cmd'";
- while(<F>) {
- my $c = $_;
- $c =~ s/^\s*//g;
- $c =~ s/\n$//g;
- next if ($c eq $sender and $suppress_from);
- push @cc, $c;
- printf("(cc-cmd) Adding cc: %s from: '%s'\n",
- $c, $cc_cmd) unless $quiet;
- }
- close F
- or die "(cc-cmd) failed to close pipe to '$cc_cmd'";
- }
+ push @to, recipients_cmd("to-cmd", "to", $to_cmd, $t)
+ if defined $to_cmd;
+ push @cc, recipients_cmd("cc-cmd", "cc", $cc_cmd, $t)
+ if defined $cc_cmd && !$suppress_cc{'cccmd'};
if ($broken_encoding{$t} && !$has_content_type) {
$has_content_type = 1;
@@ -1330,6 +1323,30 @@ foreach my $t (@files) {
$message_id = undef;
}
+# Execute a command (e.g. $to_cmd) to get a list of email addresses
+# and return a results array
+sub recipients_cmd {
+ my ($prefix, $what, $cmd, $file) = @_;
+
+ my $sanitized_sender = sanitize_address($sender);
+ my @addresses = ();
+ open(F, "$cmd \Q$file\E |")
+ or die "($prefix) Could not execute '$cmd'";
+ while(<F>) {
+ my $address = $_;
+ $address =~ s/^\s*//g;
+ $address =~ s/\s*$//g;
+ $address = sanitize_address($address);
+ next if ($address eq $sanitized_sender and $suppress_from);
+ push @addresses, $address;
+ printf("($prefix) Adding %s: %s from: '%s'\n",
+ $what, $address, $cmd) unless $quiet;
+ }
+ close F
+ or die "($prefix) failed to close pipe to '$cmd'";
+ return @addresses;
+}
+
cleanup_compose_files();
sub cleanup_compose_files() {
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index a298eb043..ba11c00c7 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -201,6 +201,24 @@ test_expect_success $PREREQ 'Prompting works' '
grep "^To: to@example.com\$" msgtxt1
'
+test_expect_success $PREREQ 'tocmd works' '
+ clean_fake_sendmail &&
+ cp $patches tocmd.patch &&
+ echo tocmd--tocmd@example.com >>tocmd.patch &&
+ {
+ echo "#!$SHELL_PATH"
+ echo sed -n -e s/^tocmd--//p \"\$1\"
+ } > tocmd-sed &&
+ chmod +x tocmd-sed &&
+ git send-email \
+ --from="Example <nobody@example.com>" \
+ --to-cmd=./tocmd-sed \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ tocmd.patch \
+ &&
+ grep "^To: tocmd@example.com" msgtxt1
+'
+
test_expect_success $PREREQ 'cccmd works' '
clean_fake_sendmail &&
cp $patches cccmd.patch &&