{"thread":{"id":"25207","subject":"Re: threaded patch series","startedAt":"2010-09-23T09:05:38Z","lastAt":"2010-09-24T17:03:00Z","messageCount":15,"participants":["Joe Perches","Ævar Arnfjörð Bjarmason","matt mooney","Junio C Hamano","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"151351","messageId":"1285232738.31572.6.camel@Joe-Laptop","threadId":"25207","inReplyTo":"Pine.LNX.4.64.1009231054230.15528@ask.diku.dk","subject":"Re: threaded patch series","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-23T09:05:38Z","receivedAt":"2010-09-23T09:05:38Z","isPatch":false,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"On Thu, 2010-09-23 at 10:55 +0200, Julia Lawall wrote:\n> I made some changes to git-send-email to get it to send mail to different \n> people, ie a different set of addresses for each patch.  Is that now \n> possible with the standard version?  If not I can submit a patch with my \n> changes at some point.\n\nI believe it's not currently possible to have\ndifferent \"to:\" addresses in a git send-email\npatch series and that could be a useful patch\nto submit.\n"},{"id":"151375","messageId":"1285262237.31572.18.camel@Joe-Laptop","threadId":"25207","inReplyTo":"Pine.LNX.4.64.1009231757090.11585@ask.diku.dk","subject":"[RFC PATCH] sit-send-email.pl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-23T17:17:17Z","receivedAt":"2010-09-23T17:17:17Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"On Thu, 2010-09-23 at 17:58 +0200, Julia Lawall wrote:\n> On Thu, 23 Sep 2010, Joe Perches wrote:\n> > On Thu, 2010-09-23 at 16:00 +0400, Vasiliy Kulikov wrote:\n> > > On Thu, Sep 23, 2010 at 13:09 +0400, Vasiliy Kulikov wrote:\n> > > > On Thu, Sep 23, 2010 at 10:55 +0200, Julia Lawall wrote:\n> > > > > I made some changes to git-send-email to get it to send mail to different \n> > > > > people, ie a different set of addresses for each patch.  Is that now \n> > > > > possible with the standard version?  If not I can submit a patch with my \n> > > > > changes at some point.\n> > > > I use git-send-email --cc-cmd=script_to_form_cc_list.\n> > I believe that Julia means some mechanism to vary the\n> > \"to\" addresses for each patch, ie: some \"--to-cmd=cmd\".\n> Yes, sort of.  I took the strategy of precomputing the To addresses, so I \n> just have a collection of files that have different To and Cc addresses.  \n> But a --to-cmd option seems like a good idea too.\n\nPerhaps something like this?\n\nLightly tested only.\n\nI know there's a test harness in git, but\nI don't know how to wire up the new options.\n\nSigned-off-by: Joe Perches <joe@perches.com>\n---\n git-send-email.perl |   25 +++++++++++++++++++++++--\n 1 files changed, 23 insertions(+), 2 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 6dab3bf..8e8e4c4 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -70,6 +70,7 @@ git send-email [options] <file | directory | rev-list options >\n \n   Automating:\n     --identity              <str>  * Use the sendemail.<id> options.\n+    --to-cmd                <str>  * Email To: via `<str> \\$patch_path`\n     --cc-cmd                <str>  * Email Cc: via `<str> \\$patch_path`\n     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.\n     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.\n@@ -187,7 +188,8 @@ sub do_edit {\n }\n \n # Variables with corresponding config settings\n-my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);\n+my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);\n+my ($to_cmd, $cc_cmd);\n my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);\n my ($validate, $confirm);\n@@ -214,6 +216,7 @@ my %config_settings = (\n     \"smtppass\" => \\$smtp_authpass,\n \t\"smtpdomain\" => \\$smtp_domain,\n     \"to\" => \\@to,\n+    \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@initial_cc,\n     \"cccmd\" => \\$cc_cmd,\n     \"aliasfiletype\" => \\$aliasfiletype,\n@@ -272,6 +275,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n                     \"in-reply-to=s\" => \\$initial_reply_to,\n \t\t    \"subject=s\" => \\$initial_subject,\n \t\t    \"to=s\" => \\@to,\n+\t\t    \"to-cmd=s\" => \\$to_cmd,\n \t\t    \"no-to\" => \\$no_to,\n \t\t    \"cc=s\" => \\@initial_cc,\n \t\t    \"no-cc\" => \\$no_cc,\n@@ -711,7 +715,7 @@ if (!defined $sender) {\n \t$prompting++;\n }\n \n-if (!@to) {\n+if (!@to && $to_cmd eq \"\") {\n \tmy $to = ask(\"Who should the emails be sent to? \");\n \tpush @to, parse_address_line($to) if defined $to; # sanitized/validated later\n \t$prompting++;\n@@ -1238,6 +1242,23 @@ foreach my $t (@files) {\n \t}\n \tclose F;\n \n+\tif (defined $to_cmd) {\n+\t\topen(F, \"$to_cmd \\Q$t\\E |\")\n+\t\t\tor die \"(to-cmd) Could not execute '$to_cmd'\";\n+\t\twhile(<F>) {\n+\t\t\tmy $t = $_;\n+\t\t\t$t =~ s/^\\s*//g;\n+\t\t\t$t =~ s/\\n$//g;\n+\t\t\tnext if ($t eq $sender and $suppress_from);\n+\t\t\tpush @to, parse_address_line($t)\n+\t\t\t    if defined $t; # sanitized/validated later\n+\t\t\tprintf(\"(to-cmd) Adding To: %s from: '%s'\\n\",\n+\t\t\t\t$t, $to_cmd) unless $quiet;\n+\t\t}\n+\t\tclose F\n+\t\t\tor die \"(to-cmd) failed to close pipe to '$to_cmd'\";\n+\t}\n+\n \tif (defined $cc_cmd && !$suppress_cc{'cccmd'}) {\n \t\topen(F, \"$cc_cmd \\Q$t\\E |\")\n \t\t\tor die \"(cc-cmd) Could not execute '$cc_cmd'\";\n"},{"id":"151376","messageId":"AANLkTin_Y8w4ujNGTqGJPNDNfYz7hcjBVLcOG0emBjYn@mail.gmail.com","threadId":"25207","inReplyTo":"1285262237.31572.18.camel@Joe-Laptop","subject":"Re: [RFC PATCH] sit-send-email.pl: Add --to-cmd","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-09-23T17:29:16Z","receivedAt":"2010-09-23T17:29:16Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Sep 23, 2010 at 17:17, Joe Perches <joe@perches.com> wrote:\n> On Thu, 2010-09-23 at 17:58 +0200, Julia Lawall wrote:\n>> On Thu, 23 Sep 2010, Joe Perches wrote:\n>> > On Thu, 2010-09-23 at 16:00 +0400, Vasiliy Kulikov wrote:\n>> > > On Thu, Sep 23, 2010 at 13:09 +0400, Vasiliy Kulikov wrote:\n>> > > > On Thu, Sep 23, 2010 at 10:55 +0200, Julia Lawall wrote:\n>> > > > > I made some changes to git-send-email to get it to send mail to different\n>> > > > > people, ie a different set of addresses for each patch.  Is that now\n>> > > > > possible with the standard version?  If not I can submit a patch with my\n>> > > > > changes at some point.\n>> > > > I use git-send-email --cc-cmd=script_to_form_cc_list.\n>> > I believe that Julia means some mechanism to vary the\n>> > \"to\" addresses for each patch, ie: some \"--to-cmd=cmd\".\n>> Yes, sort of.  I took the strategy of precomputing the To addresses, so I\n>> just have a collection of files that have different To and Cc addresses.\n>> But a --to-cmd option seems like a good idea too.\n>\n> Perhaps something like this?\n>\n> Lightly tested only.\n>\n> I know there's a test harness in git, but\n> I don't know how to wire up the new options.\n\nYou'd add the tests to t9001-send-email.sh and --tocmd out to some\nprogram you create. Is there anything in particular you need help\nwith?\n\n> Signed-off-by: Joe Perches <joe@perches.com>\n> ---\n>  git-send-email.perl |   25 +++++++++++++++++++++++--\n>  1 files changed, 23 insertions(+), 2 deletions(-)\n>\n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index 6dab3bf..8e8e4c4 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -70,6 +70,7 @@ git send-email [options] <file | directory | rev-list options >\n>\n>   Automating:\n>     --identity              <str>  * Use the sendemail.<id> options.\n> +    --to-cmd                <str>  * Email To: via `<str> \\$patch_path`\n>     --cc-cmd                <str>  * Email Cc: via `<str> \\$patch_path`\n>     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.\n>     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.\n> @@ -187,7 +188,8 @@ sub do_edit {\n>  }\n>\n>  # Variables with corresponding config settings\n> -my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);\n> +my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);\n> +my ($to_cmd, $cc_cmd);\n>  my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n>  my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);\n>  my ($validate, $confirm);\n> @@ -214,6 +216,7 @@ my %config_settings = (\n>     \"smtppass\" => \\$smtp_authpass,\n>        \"smtpdomain\" => \\$smtp_domain,\n>     \"to\" => \\@to,\n> +    \"tocmd\" => \\$to_cmd,\n>     \"cc\" => \\@initial_cc,\n>     \"cccmd\" => \\$cc_cmd,\n>     \"aliasfiletype\" => \\$aliasfiletype,\n> @@ -272,6 +275,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n>                     \"in-reply-to=s\" => \\$initial_reply_to,\n>                    \"subject=s\" => \\$initial_subject,\n>                    \"to=s\" => \\@to,\n> +                   \"to-cmd=s\" => \\$to_cmd,\n>                    \"no-to\" => \\$no_to,\n>                    \"cc=s\" => \\@initial_cc,\n>                    \"no-cc\" => \\$no_cc,\n> @@ -711,7 +715,7 @@ if (!defined $sender) {\n>        $prompting++;\n>  }\n>\n> -if (!@to) {\n> +if (!@to && $to_cmd eq \"\") {\n\nWhy compare $to_cmd to \"\" instead of checking definedness?\n\n>        my $to = ask(\"Who should the emails be sent to? \");\n>        push @to, parse_address_line($to) if defined $to; # sanitized/validated later\n>        $prompting++;\n> @@ -1238,6 +1242,23 @@ foreach my $t (@files) {\n>        }\n>        close F;\n>\n> +       if (defined $to_cmd) {\n> +               open(F, \"$to_cmd \\Q$t\\E |\")\n\nquotemeta() is for escaping regexes, not shell syntax. You probably\nwant IPC::Open2 or PC::Open3's functions which'll escape arguments for\nyou.\n\nAlso \"open my $f\" is better, but I see the existing code uses glob\nfilehandles (urghl).\n\n> +                       or die \"(to-cmd) Could not execute '$to_cmd'\";\n> +               while(<F>) {\n> +                       my $t = $_;\n> +                       $t =~ s/^\\s*//g;\n> +                       $t =~ s/\\n$//g;\n\nShouldn't this just be:\n\n    while (my $address = <$f>) {\n        chomp $address;\n        ...\n\nI.e. do you need to strip whitespace from the beginning of the string?\n\n> +                       next if ($t eq $sender and $suppress_from);\n> +                       push @to, parse_address_line($t)\n> +                           if defined $t; # sanitized/validated later\n> +                       printf(\"(to-cmd) Adding To: %s from: '%s'\\n\",\n> +                               $t, $to_cmd) unless $quiet;\n> +               }\n> +               close F\n> +                       or die \"(to-cmd) failed to close pipe to '$to_cmd'\";\n> +       }\n\nclose F could be skipped if we used lexical handes, but see urghl\nabove.\n"},{"id":"151379","messageId":"1285263993.31572.25.camel@Joe-Laptop","threadId":"25207","inReplyTo":"AANLkTin_Y8w4ujNGTqGJPNDNfYz7hcjBVLcOG0emBjYn@mail.gmail.com","subject":"Re: [RFC PATCH] sit-send-email.pl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-23T17:46:33Z","receivedAt":"2010-09-23T17:46:33Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"On Thu, 2010-09-23 at 17:29 +0000, Ævar Arnfjörð Bjarmason wrote:\n> On Thu, Sep 23, 2010 at 17:17, Joe Perches <joe@perches.com> wrote:\n> > I know there's a test harness in git, but\n> > I don't know how to wire up the new options.\n> You'd add the tests to t9001-send-email.sh and --tocmd out to some\n> program you create. Is there anything in particular you need help\n> with?\n\nJust the doing.  I was (am) being lazy.\n\n> > -if (!@to) {\n> > +if (!@to && $to_cmd eq \"\") {\n> \n> Why compare $to_cmd to \"\" instead of checking definedness?\n\nNo real reason.  Using define is the style used in the rest of\nthe file and it should be changed.\n\n> > @@ -1238,6 +1242,23 @@ foreach my $t (@files) {\n> >        }\n> >        close F;\n> >\n> > +       if (defined $to_cmd) {\n> > +               open(F, \"$to_cmd \\Q$t\\E |\")\n> \n> quotemeta() is for escaping regexes, not shell syntax. You probably\n> want IPC::Open2 or PC::Open3's functions which'll escape arguments for\n> you.\n\nI just copied the style from the equivalent cc_cmd section below,\nso if it's necessary, it should be changed there too.\n\n> I.e. do you need to strip whitespace from the beginning of the string?\n\nI think so.\n"},{"id":"151380","messageId":"AANLkTinCx=+n6bMZw4tQqrQ7WC1o_aeGG_n_PxywTyb8@mail.gmail.com","threadId":"25207","inReplyTo":"1285263993.31572.25.camel@Joe-Laptop","subject":"Re: [RFC PATCH] sit-send-email.pl: Add --to-cmd","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-09-23T17:50:05Z","receivedAt":"2010-09-23T17:50:05Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Sep 23, 2010 at 17:46, Joe Perches <joe@perches.com> wrote:\n> On Thu, 2010-09-23 at 17:29 +0000, Ævar Arnfjörð Bjarmason wrote:\n>> On Thu, Sep 23, 2010 at 17:17, Joe Perches <joe@perches.com> wrote:\n>> > I know there's a test harness in git, but\n>> > I don't know how to wire up the new options.\n>> You'd add the tests to t9001-send-email.sh and --tocmd out to some\n>> program you create. Is there anything in particular you need help\n>> with?\n>\n> Just the doing.  I was (am) being lazy.\n>\n>> > -if (!@to) {\n>> > +if (!@to && $to_cmd eq \"\") {\n>>\n>> Why compare $to_cmd to \"\" instead of checking definedness?\n>\n> No real reason.  Using define is the style used in the rest of\n> the file and it should be changed.\n>\n>> > @@ -1238,6 +1242,23 @@ foreach my $t (@files) {\n>> >        }\n>> >        close F;\n>> >\n>> > +       if (defined $to_cmd) {\n>> > +               open(F, \"$to_cmd \\Q$t\\E |\")\n>>\n>> quotemeta() is for escaping regexes, not shell syntax. You probably\n>> want IPC::Open2 or PC::Open3's functions which'll escape arguments for\n>> you.\n>\n> I just copied the style from the equivalent cc_cmd section below,\n> so if it's necessary, it should be changed there too.\n>\n>> I.e. do you need to strip whitespace from the beginning of the string?\n>\n> I think so.\n\nThis all sounds reasonable, but I really need to go through\ngit-send-email.perl and fix all these bugs at some point...\n"},{"id":"151385","messageId":"1285267520.31572.34.camel@Joe-Laptop","threadId":"25207","inReplyTo":"AANLkTinCx=+n6bMZw4tQqrQ7WC1o_aeGG_n_PxywTyb8@mail.gmail.com","subject":"[PATCH V2] git-send-email.perl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-23T18:45:20Z","receivedAt":"2010-09-23T18:45:20Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"Add the ability to use a command line --to-cmd=cmd\nto create the list of \"To:\" addresses.\n\nSigned-off-by: Joe Perches <joe@perches.com>\n---\n Documentation/git-send-email.txt |    8 +++++++-\n git-send-email.perl              |   25 +++++++++++++++++++++++--\n t/t9001-send-email.sh            |   18 ++++++++++++++++++\n 3 files changed, 48 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex c283084..fff97a3 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -97,7 +97,7 @@ See the CONFIGURATION section for 'sendemail.multiedit'.\n \tSpecify the primary recipient of the emails generated. Generally, this\n \twill be the upstream maintainer of the project involved. Default is the\n \tvalue of the 'sendemail.to' configuration value; if that is unspecified,\n-\tthis will be prompted for.\n+\tand --to-cmd is not specified, this will be prompted for.\n +\n The --to option must be repeated for each user you want on the to list.\n \n@@ -177,6 +177,12 @@ user is prompted for a password while the input is masked for privacy.\n Automating\n ~~~~~~~~~~\n \n+--to-cmd=<command>::\n+\tSpecify a command to execute once per patch file which\n+\tshould generate patch file specific \"To:\" entries.\n+\tOutput of this command must be single email address per line.\n+\tDefault is the value of 'sendemail.tocmd' configuration value.\n+\n --cc-cmd=<command>::\n \tSpecify a command to execute once per patch file which\n \tshould generate patch file specific \"Cc:\" entries.\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 6dab3bf..fa8da8b 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -70,6 +70,7 @@ git send-email [options] <file | directory | rev-list options >\n \n   Automating:\n     --identity              <str>  * Use the sendemail.<id> options.\n+    --to-cmd                <str>  * Email To: via `<str> \\$patch_path`\n     --cc-cmd                <str>  * Email Cc: via `<str> \\$patch_path`\n     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.\n     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.\n@@ -187,7 +188,8 @@ sub do_edit {\n }\n \n # Variables with corresponding config settings\n-my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);\n+my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);\n+my ($to_cmd, $cc_cmd);\n my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);\n my ($validate, $confirm);\n@@ -214,6 +216,7 @@ my %config_settings = (\n     \"smtppass\" => \\$smtp_authpass,\n \t\"smtpdomain\" => \\$smtp_domain,\n     \"to\" => \\@to,\n+    \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@initial_cc,\n     \"cccmd\" => \\$cc_cmd,\n     \"aliasfiletype\" => \\$aliasfiletype,\n@@ -272,6 +275,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n                     \"in-reply-to=s\" => \\$initial_reply_to,\n \t\t    \"subject=s\" => \\$initial_subject,\n \t\t    \"to=s\" => \\@to,\n+\t\t    \"to-cmd=s\" => \\$to_cmd,\n \t\t    \"no-to\" => \\$no_to,\n \t\t    \"cc=s\" => \\@initial_cc,\n \t\t    \"no-cc\" => \\$no_cc,\n@@ -711,7 +715,7 @@ if (!defined $sender) {\n \t$prompting++;\n }\n \n-if (!@to) {\n+if (!@to && !defined $to_cmd) {\n \tmy $to = ask(\"Who should the emails be sent to? \");\n \tpush @to, parse_address_line($to) if defined $to; # sanitized/validated later\n \t$prompting++;\n@@ -1238,6 +1242,23 @@ foreach my $t (@files) {\n \t}\n \tclose F;\n \n+\tif (defined $to_cmd) {\n+\t\topen(F, \"$to_cmd \\Q$t\\E |\")\n+\t\t\tor die \"(to-cmd) Could not execute '$to_cmd'\";\n+\t\twhile(<F>) {\n+\t\t\tmy $t = $_;\n+\t\t\t$t =~ s/^\\s*//g;\n+\t\t\t$t =~ s/\\n$//g;\n+\t\t\tnext if ($t eq $sender and $suppress_from);\n+\t\t\tpush @to, parse_address_line($t)\n+\t\t\t    if defined $t; # sanitized/validated later\n+\t\t\tprintf(\"(to-cmd) Adding To: %s from: '%s'\\n\",\n+\t\t\t\t$t, $to_cmd) unless $quiet;\n+\t\t}\n+\t\tclose F\n+\t\t\tor die \"(to-cmd) failed to close pipe to '$to_cmd'\";\n+\t}\n+\n \tif (defined $cc_cmd && !$suppress_cc{'cccmd'}) {\n \t\topen(F, \"$cc_cmd \\Q$t\\E |\")\n \t\t\tor die \"(cc-cmd) Could not execute '$cc_cmd'\";\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 71b3df9..36cf421 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -201,6 +201,24 @@ test_expect_success $PREREQ 'Prompting works' '\n \t\tgrep \"^To: to@example.com\\$\" msgtxt1\n '\n \n+test_expect_success $PREREQ 'tocmd works' '\n+\tclean_fake_sendmail &&\n+\tcp $patches tocmd.patch &&\n+\techo tocmd--tocmd@example.com >>tocmd.patch &&\n+\t{\n+\t  echo \"#!$SHELL_PATH\"\n+\t  echo sed -n -e s/^tocmd--//p \\\"\\$1\\\"\n+\t} > tocmd-sed &&\n+\tchmod +x tocmd-sed &&\n+\tgit send-email \\\n+\t\t--from=\"Example <nobody@example.com>\" \\\n+\t\t--to-cmd=./tocmd-sed \\\n+\t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\ttocmd.patch \\\n+\t\t&&\n+\tgrep \"^To: tocmd@example.com\" msgtxt1\n+'\n+\n test_expect_success $PREREQ 'cccmd works' '\n \tclean_fake_sendmail &&\n \tcp $patches cccmd.patch &&\n"},{"id":"151388","messageId":"AANLkTin7KKqtvJrioiAspGiN8-Gpe+gzd0eC48LaNa7P@mail.gmail.com","threadId":"25207","inReplyTo":"1285267520.31572.34.camel@Joe-Laptop","subject":"Re: [PATCH V2] git-send-email.perl: Add --to-cmd","fromName":"matt mooney","fromEmail":"mfmooney@gmail.com","sentAt":"2010-09-23T19:57:35Z","receivedAt":"2010-09-23T19:57:35Z","isPatch":true,"sender":{"key":"mfmooney@gmail.com","avatar":null},"body":"On Thu, Sep 23, 2010 at 11:45 AM, Joe Perches <joe@perches.com> wrote:\n> Add the ability to use a command line --to-cmd=cmd\n> to create the list of \"To:\" addresses.\n>\n> Signed-off-by: Joe Perches <joe@perches.com>\n> ---\n>  Documentation/git-send-email.txt |    8 +++++++-\n>  git-send-email.perl              |   25 +++++++++++++++++++++++--\n>  t/t9001-send-email.sh            |   18 ++++++++++++++++++\n>  3 files changed, 48 insertions(+), 3 deletions(-)\n\nLooks reasonable to me. Nice work getting on this quickly ;)\n\n-mfm\n\n-- \nGPG-Key: 9AFE00EA\n"},{"id":"151410","messageId":"7v62xwqe7i.fsf@alter.siamese.dyndns.org","threadId":"25207","inReplyTo":"1285267520.31572.34.camel@Joe-Laptop","subject":"Re: [PATCH V2] git-send-email.perl: Add --to-cmd","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-09-23T22:37:05Z","receivedAt":"2010-09-23T22:37:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joe Perches <joe@perches.com> writes:\n\n> +\tif (defined $to_cmd) {\n> +\t\topen(F, \"$to_cmd \\Q$t\\E |\")\n> +\t\t\tor die \"(to-cmd) Could not execute '$to_cmd'\";\n> +\t\twhile(<F>) {\n> +\t\t\tmy $t = $_;\n\n\"my $t\" masks another $t in the outer scope; technically not a bug, but\nquestionable as a style.\n\n> +\t\t\t$t =~ s/^\\s*//g;\n> +\t\t\t$t =~ s/\\n$//g;\n> +\t\t\tnext if ($t eq $sender and $suppress_from);\n> +\t\t\tpush @to, parse_address_line($t)\n> +\t\t\t    if defined $t; # sanitized/validated later\n\nThis \"if defined $t\" makes my head hurt.  Why?\n\n * The \"while (<F>)\" loop wouldn't have given you an undef in $t in the\n   first place;\n\n * You would have got \"Use of uninitialized value\" warning at these two\n   s/// statements if $t were undef; and\n\n * Even if $t were undef, these two s/// statements would have made $t a\n   defined, empty string.\n\n> +\t\t\tprintf(\"(to-cmd) Adding To: %s from: '%s'\\n\",\n> +\t\t\t\t$t, $to_cmd) unless $quiet;\n> +\t\t}\n> +\t\tclose F\n> +\t\t\tor die \"(to-cmd) failed to close pipe to '$to_cmd'\";\n> +\t}\n\nIn any case, this whole codeblock obviously is a copy-and-paste from\ncorresponding $cc_cmd codepath, and I wonder if you can refactor the\noriginal into a common helper function first and then use it to make the\naddition of this feature a smaller patch.\n\n\tif (defined $cc_cmd) {\n        \tpush @cc, recipients_cmd($cc_cmd, 'cc');\n\t}\n        if (defined $to_cmd) {\n\t        push @to, recipients_cmd($to_cmd, 'to');\n\t}\n\nIf you did so, the first patch that refactors to create a helper function\ncan address issues Ævar raised in the review to clean things up, no?\n\nI notice that you use parse_address_line() while $cc_cmd codepath doesn't.\nI haven't studied other codepaths deeply, but my gut feeling is that the\nreason why the $cc_cmd codepath does not call parse_address_line() before\npushing the result to @cc is _not_ because strings on @cc shouldn't be\nsanitized (the codepath to parse \"Cc: \" calls parse_address_line and\npushes the result to @cc), but because the code is simply sloppy.  So I\nsuspect that it would be Ok for recipients_cmd to call parse_address_line\nunconditionally.\n\nHmm?\n"},{"id":"151415","messageId":"AANLkTin2YvPxnbCXzWsugfaGvbUUcm6n5LtwkNVxhJfC@mail.gmail.com","threadId":"25207","inReplyTo":"7v62xwqe7i.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH V2] git-send-email.perl: Add --to-cmd","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-09-23T23:16:06Z","receivedAt":"2010-09-23T23:16:06Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Sep 23, 2010 at 22:37, Junio C Hamano <gitster@pobox.com> wrote:\n> Joe Perches <joe@perches.com> writes:\n>\n>> +     if (defined $to_cmd) {\n>> +             open(F, \"$to_cmd \\Q$t\\E |\")\n>> +                     or die \"(to-cmd) Could not execute '$to_cmd'\";\n>> +             while(<F>) {\n>> +                     my $t = $_;\n>\n> \"my $t\" masks another $t in the outer scope; technically not a bug, but\n> questionable as a style.\n>\n>> +                     $t =~ s/^\\s*//g;\n>> +                     $t =~ s/\\n$//g;\n>> +                     next if ($t eq $sender and $suppress_from);\n>> +                     push @to, parse_address_line($t)\n>> +                         if defined $t; # sanitized/validated later\n>\n> This \"if defined $t\" makes my head hurt.  Why?\n>\n>  * The \"while (<F>)\" loop wouldn't have given you an undef in $t in the\n>   first place;\n>\n>  * You would have got \"Use of uninitialized value\" warning at these two\n>   s/// statements if $t were undef; and\n>\n>  * Even if $t were undef, these two s/// statements would have made $t a\n>   defined, empty string.\n\nWell spotted. Also it *can't* be undef here by definition. Since $t is\ntaken from the $_ value which comes from the <> operator. That just\nwraps readline(), which will exit the loop when it hit EOF (at which\npoint readline() *would* return undef).\n\nSo this whole business of checking for the definedness of $t doesn't\nmake any sense.\n"},{"id":"151419","messageId":"1285291098.25928.220.camel@Joe-Laptop","threadId":"25207","inReplyTo":"7v62xwqe7i.fsf@alter.siamese.dyndns.org","subject":"[PATCH V3] git-send-email.perl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-24T01:18:18Z","receivedAt":"2010-09-24T01:18:18Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"Add the ability to use a command line --to-cmd=cmd\nto create the list of \"To:\" addresses.\n\nUsed a shared routine for --cc-cmd and --to-cmd.\n\nDid not use IPC::Open2, leaving that for Ævar if\never he decides to fix the other bugs he might find.\n\nSigned-off-by: Joe Perches <joe@perches.com>\n---\n Documentation/git-send-email.txt |    8 +++++-\n git-send-email.perl              |   51 +++++++++++++++++++++++++------------\n t/t9001-send-email.sh            |   18 +++++++++++++\n 3 files changed, 59 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex c283084..fff97a3 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -97,7 +97,7 @@ See the CONFIGURATION section for 'sendemail.multiedit'.\n \tSpecify the primary recipient of the emails generated. Generally, this\n \twill be the upstream maintainer of the project involved. Default is the\n \tvalue of the 'sendemail.to' configuration value; if that is unspecified,\n-\tthis will be prompted for.\n+\tand --to-cmd is not specified, this will be prompted for.\n +\n The --to option must be repeated for each user you want on the to list.\n \n@@ -177,6 +177,12 @@ user is prompted for a password while the input is masked for privacy.\n Automating\n ~~~~~~~~~~\n \n+--to-cmd=<command>::\n+\tSpecify a command to execute once per patch file which\n+\tshould generate patch file specific \"To:\" entries.\n+\tOutput of this command must be single email address per line.\n+\tDefault is the value of 'sendemail.tocmd' configuration value.\n+\n --cc-cmd=<command>::\n \tSpecify a command to execute once per patch file which\n \tshould generate patch file specific \"Cc:\" entries.\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 6dab3bf..e148269 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -70,6 +70,7 @@ git send-email [options] <file | directory | rev-list options >\n \n   Automating:\n     --identity              <str>  * Use the sendemail.<id> options.\n+    --to-cmd                <str>  * Email To: via `<str> \\$patch_path`\n     --cc-cmd                <str>  * Email Cc: via `<str> \\$patch_path`\n     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.\n     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.\n@@ -187,7 +188,8 @@ sub do_edit {\n }\n \n # Variables with corresponding config settings\n-my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);\n+my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);\n+my ($to_cmd, $cc_cmd);\n my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);\n my ($validate, $confirm);\n@@ -214,6 +216,7 @@ my %config_settings = (\n     \"smtppass\" => \\$smtp_authpass,\n \t\"smtpdomain\" => \\$smtp_domain,\n     \"to\" => \\@to,\n+    \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@initial_cc,\n     \"cccmd\" => \\$cc_cmd,\n     \"aliasfiletype\" => \\$aliasfiletype,\n@@ -272,6 +275,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n                     \"in-reply-to=s\" => \\$initial_reply_to,\n \t\t    \"subject=s\" => \\$initial_subject,\n \t\t    \"to=s\" => \\@to,\n+\t\t    \"to-cmd=s\" => \\$to_cmd,\n \t\t    \"no-to\" => \\$no_to,\n \t\t    \"cc=s\" => \\@initial_cc,\n \t\t    \"no-cc\" => \\$no_cc,\n@@ -711,7 +715,7 @@ if (!defined $sender) {\n \t$prompting++;\n }\n \n-if (!@to) {\n+if (!@to && !defined $to_cmd) {\n \tmy $to = ask(\"Who should the emails be sent to? \");\n \tpush @to, parse_address_line($to) if defined $to; # sanitized/validated later\n \t$prompting++;\n@@ -1238,21 +1242,10 @@ foreach my $t (@files) {\n \t}\n \tclose F;\n \n-\tif (defined $cc_cmd && !$suppress_cc{'cccmd'}) {\n-\t\topen(F, \"$cc_cmd \\Q$t\\E |\")\n-\t\t\tor die \"(cc-cmd) Could not execute '$cc_cmd'\";\n-\t\twhile(<F>) {\n-\t\t\tmy $c = $_;\n-\t\t\t$c =~ s/^\\s*//g;\n-\t\t\t$c =~ s/\\n$//g;\n-\t\t\tnext if ($c eq $sender and $suppress_from);\n-\t\t\tpush @cc, $c;\n-\t\t\tprintf(\"(cc-cmd) Adding cc: %s from: '%s'\\n\",\n-\t\t\t\t$c, $cc_cmd) unless $quiet;\n-\t\t}\n-\t\tclose F\n-\t\t\tor die \"(cc-cmd) failed to close pipe to '$cc_cmd'\";\n-\t}\n+\tpush @to, recipients_cmd(\"to-cmd\", \"to\", $to_cmd, $t)\n+\t\tif defined $to_cmd;\n+\tpush @cc, recipients_cmd(\"cc-cmd\", \"cc\", $cc_cmd, $t)\n+\t\tif defined $cc_cmd && !$suppress_cc{'cccmd'};\n \n \tif ($broken_encoding{$t} && !$has_content_type) {\n \t\t$has_content_type = 1;\n@@ -1310,6 +1303,30 @@ foreach my $t (@files) {\n \t$message_id = undef;\n }\n \n+# Execute a command (ie: $to_cmd) to get a list of email addresses\n+# and return a results array\n+sub recipients_cmd(@) {\n+\tmy ($prefix, $what, $cmd, $file) = @_;\n+\n+\tmy $sanitized_sender = sanitize_address($sender);\n+\tmy @addresses = ();\n+\topen(F, \"$cmd \\Q$file\\E |\")\n+\t    or die \"($prefix) Could not execute '$cmd'\";\n+\twhile(<F>) {\n+\t\tmy $address = $_;\n+\t\t$address =~ s/^\\s*//g;\n+\t\t$address =~ s/\\n$//g;\n+\t\t$address = sanitize_address($address);\n+\t\tnext if ($address eq $sanitized_sender and $suppress_from);\n+\t\tpush @addresses, $address;\n+\t\tprintf(\"($prefix) Adding %s: %s from: '%s'\\n\",\n+\t\t       $what, $address, $cmd) unless $quiet;\n+\t\t}\n+\tclose F\n+\t    or die \"($prefix) failed to close pipe to '$cmd'\";\n+\treturn @addresses;\n+}\n+\n cleanup_compose_files();\n \n sub cleanup_compose_files() {\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 71b3df9..36cf421 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -201,6 +201,24 @@ test_expect_success $PREREQ 'Prompting works' '\n \t\tgrep \"^To: to@example.com\\$\" msgtxt1\n '\n \n+test_expect_success $PREREQ 'tocmd works' '\n+\tclean_fake_sendmail &&\n+\tcp $patches tocmd.patch &&\n+\techo tocmd--tocmd@example.com >>tocmd.patch &&\n+\t{\n+\t  echo \"#!$SHELL_PATH\"\n+\t  echo sed -n -e s/^tocmd--//p \\\"\\$1\\\"\n+\t} > tocmd-sed &&\n+\tchmod +x tocmd-sed &&\n+\tgit send-email \\\n+\t\t--from=\"Example <nobody@example.com>\" \\\n+\t\t--to-cmd=./tocmd-sed \\\n+\t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\ttocmd.patch \\\n+\t\t&&\n+\tgrep \"^To: tocmd@example.com\" msgtxt1\n+'\n+\n test_expect_success $PREREQ 'cccmd works' '\n \tclean_fake_sendmail &&\n \tcp $patches cccmd.patch &&\n"},{"id":"151420","messageId":"1285291254.25928.223.camel@Joe-Laptop","threadId":"25207","inReplyTo":"7v62xwqe7i.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH V2] git-send-email.perl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-24T01:20:54Z","receivedAt":"2010-09-24T01:20:54Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"On Thu, 2010-09-23 at 15:37 -0700, Junio C Hamano wrote:\n> Joe Perches <joe@perches.com> writes:\n> \n> > +\tif (defined $to_cmd) {\n> > +\t\topen(F, \"$to_cmd \\Q$t\\E |\")\n> > +\t\t\tor die \"(to-cmd) Could not execute '$to_cmd'\";\n> > +\t\twhile(<F>) {\n> > +\t\t\tmy $t = $_;\n> \n> \"my $t\" masks another $t in the outer scope; technically not a bug, but\n> questionable as a style.\n> \n> > +\t\t\t$t =~ s/^\\s*//g;\n> > +\t\t\t$t =~ s/\\n$//g;\n> > +\t\t\tnext if ($t eq $sender and $suppress_from);\n> > +\t\t\tpush @to, parse_address_line($t)\n> > +\t\t\t    if defined $t; # sanitized/validated later\n> \n> This \"if defined $t\" makes my head hurt.  Why?\n> \n>  * The \"while (<F>)\" loop wouldn't have given you an undef in $t in the\n>    first place;\n> \n>  * You would have got \"Use of uninitialized value\" warning at these two\n>    s/// statements if $t were undef; and\n> \n>  * Even if $t were undef, these two s/// statements would have made $t a\n>    defined, empty string.\n\nall true.\n\n> > +\t\t\tprintf(\"(to-cmd) Adding To: %s from: '%s'\\n\",\n> > +\t\t\t\t$t, $to_cmd) unless $quiet;\n> > +\t\t}\n> > +\t\tclose F\n> > +\t\t\tor die \"(to-cmd) failed to close pipe to '$to_cmd'\";\n> > +\t}\n> \n> In any case, this whole codeblock obviously is a copy-and-paste from\n> corresponding $cc_cmd codepath, and I wonder if you can refactor the\n> original into a common helper function first and then use it to make the\n> addition of this feature a smaller patch.\n> \n> \tif (defined $cc_cmd) {\n>         \tpush @cc, recipients_cmd($cc_cmd, 'cc');\n> \t}\n>         if (defined $to_cmd) {\n> \t        push @to, recipients_cmd($to_cmd, 'to');\n> \t}\n\nOverall, I believe it'll be more code, but all right.\n\n> If you did so, the first patch that refactors to create a helper function\n> can address issues Ævar raised in the review to clean things up, no?\n\n> I notice that you use parse_address_line() while $cc_cmd codepath doesn't.\n> I haven't studied other codepaths deeply, but my gut feeling is that the\n> reason why the $cc_cmd codepath does not call parse_address_line() before\n> pushing the result to @cc is _not_ because strings on @cc shouldn't be\n> sanitized (the codepath to parse \"Cc: \" calls parse_address_line and\n> pushes the result to @cc), but because the code is simply sloppy.\n\nProbably, I wrote some of those lines...\n"},{"id":"151488","messageId":"m3lj6rgnub.fsf@localhost.localdomain","threadId":"25207","inReplyTo":"1285291098.25928.220.camel@Joe-Laptop","subject":"Re: [PATCH V3] git-send-email.perl: Add --to-cmd","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-09-24T15:32:25Z","receivedAt":"2010-09-24T15:32:25Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Joe Perches <joe@perches.com> writes:\n\n> +# Execute a command (ie: $to_cmd) to get a list of email addresses\n> +# and return a results array\n> +sub recipients_cmd(@) {\n\nDo not use subroutine prototypes: they do not do what you think they\ndo.  In this case using prototype is unnecessary and can be dangerous.\n\n> +\tmy ($prefix, $what, $cmd, $file) = @_;\n> +\n> +\tmy $sanitized_sender = sanitize_address($sender);\n> +\tmy @addresses = ();\n> +\topen(F, \"$cmd \\Q$file\\E |\")\n\nFor the future: use lexical filehandles instead of globals\n\n  +\topen(my $fh, \"$cmd \\Q$file\\E |\")\n\n\n> +\t    or die \"($prefix) Could not execute '$cmd'\";\n\nYou should use quote_command from gitweb/gitweb.perl (should probably\nmake it into Git.pm):\n\n  # quote the given arguments for passing them to the shell\n  # quote_command(\"command\", \"arg 1\", \"arg with ' and ! characters\")\n  # => \"'command' 'arg 1' 'arg with '\\'' and '\\!' characters'\"\n  # Try to avoid using this function wherever possible.\n  sub quote_command {\n  \treturn join(' ',\n  \t\tmap { my $a = $_; $a =~ s/(['!])/'\\\\$1'/g; \"'$a'\" } @_ );\n  }\n\nOr use String::ShellQuote :-)\n\nBut that is for a cleanup patch; you are using what it is already\nthere.\n\n> +\twhile(<F>) {\n> +\t\tmy $address = $_;\n> +\t\t$address =~ s/^\\s*//g;\n> +\t\t$address =~ s/\\n$//g;\n\nHmmm... why does it remove leading, but not trailing whitespace?\n\n> +\t\t$address = sanitize_address($address);\n> +\t\tnext if ($address eq $sanitized_sender and $suppress_from);\n> +\t\tpush @addresses, $address;\n> +\t\tprintf(\"($prefix) Adding %s: %s from: '%s'\\n\",\n> +\t\t       $what, $address, $cmd) unless $quiet;\n> +\t\t}\n> +\tclose F\n> +\t    or die \"($prefix) failed to close pipe to '$cmd'\";\n> +\treturn @addresses;\n> +}\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"151503","messageId":"1285344394.11616.23.camel@Joe-Laptop","threadId":"25207","inReplyTo":"m3lj6rgnub.fsf@localhost.localdomain","subject":"Re: [PATCH V3] git-send-email.perl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-24T16:06:34Z","receivedAt":"2010-09-24T16:06:34Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"On Fri, 2010-09-24 at 08:32 -0700, Jakub Narebski wrote:\n> Joe Perches <joe@perches.com> writes:\n> > +# Execute a command (ie: $to_cmd) to get a list of email addresses\n> > +# and return a results array\n> > +sub recipients_cmd(@) {\n> Do not use subroutine prototypes: they do not do what you think they\n> do.  In this case using prototype is unnecessary and can be dangerous.\n \nIt can be removed.  I was following the form of the\nother returned array in the code.\n\nsub unique_email_list(@) {\n\n> > +\twhile(<F>) {\n> > +\t\tmy $address = $_;\n> > +\t\t$address =~ s/^\\s*//g;\n> > +\t\t$address =~ s/\\n$//g;\n> Hmmm... why does it remove leading, but not trailing whitespace?\n \nUnmodified from the current.  I agree it should do both.\n"},{"id":"151513","messageId":"AANLkTinGZ1H3ODYwRhvzya_UkA8t2QTW7cEyjb2Hx_7M@mail.gmail.com","threadId":"25207","inReplyTo":"1285344394.11616.23.camel@Joe-Laptop","subject":"Re: [PATCH V3] git-send-email.perl: Add --to-cmd","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-09-24T16:47:36Z","receivedAt":"2010-09-24T16:47:36Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Fri, Sep 24, 2010 at 16:06, Joe Perches <joe@perches.com> wrote:\n> On Fri, 2010-09-24 at 08:32 -0700, Jakub Narebski wrote:\n>> Joe Perches <joe@perches.com> writes:\n>> > +# Execute a command (ie: $to_cmd) to get a list of email addresses\n>> > +# and return a results array\n>> > +sub recipients_cmd(@) {\n>> Do not use subroutine prototypes: they do not do what you think they\n>> do.  In this case using prototype is unnecessary and can be dangerous.\n>\n> It can be removed.  I was following the form of the\n> other returned array in the code.\n\nWhile we generally follow the rule that you should use the style of\nthe existing code, I think resaonable to discard that when the\nsurrounding code with less than wizard-level understanding of the\nlanguage.\n\nIn any case most of git-send-email.perl doesn't use prototypes, it's\njust 2-3 subs out of ~30.\n"},{"id":"151514","messageId":"1285347780.11616.97.camel@Joe-Laptop","threadId":"25207","inReplyTo":"AANLkTinGZ1H3ODYwRhvzya_UkA8t2QTW7cEyjb2Hx_7M@mail.gmail.com","subject":"[PATCH V4] git-send-email.perl: Add --to-cmd","fromName":"Joe Perches","fromEmail":"joe@perches.com","sentAt":"2010-09-24T17:03:00Z","receivedAt":"2010-09-24T17:03:00Z","isPatch":true,"sender":{"key":"joe@perches.com","avatar":"https://avatars.githubusercontent.com/u/13122723?v=4"},"body":"Add the ability to use a command line --to-cmd=cmd\nto create the list of \"To:\" addresses.\n\nUsed a shared routine for --cc-cmd and --to-cmd.\n\nDid not use IPC::Open2, leaving that for Ævar if\never he decides to fix the other bugs he might find.\n\nSigned-off-by: Joe Perches <joe@perches.com>\n---\n Documentation/git-send-email.txt |    8 +++++-\n git-send-email.perl              |   51 +++++++++++++++++++++++++------------\n t/t9001-send-email.sh            |   18 +++++++++++++\n 3 files changed, 59 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex c283084..fff97a3 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -97,7 +97,7 @@ See the CONFIGURATION section for 'sendemail.multiedit'.\n \tSpecify the primary recipient of the emails generated. Generally, this\n \twill be the upstream maintainer of the project involved. Default is the\n \tvalue of the 'sendemail.to' configuration value; if that is unspecified,\n-\tthis will be prompted for.\n+\tand --to-cmd is not specified, this will be prompted for.\n +\n The --to option must be repeated for each user you want on the to list.\n \n@@ -177,6 +177,12 @@ user is prompted for a password while the input is masked for privacy.\n Automating\n ~~~~~~~~~~\n \n+--to-cmd=<command>::\n+\tSpecify a command to execute once per patch file which\n+\tshould generate patch file specific \"To:\" entries.\n+\tOutput of this command must be single email address per line.\n+\tDefault is the value of 'sendemail.tocmd' configuration value.\n+\n --cc-cmd=<command>::\n \tSpecify a command to execute once per patch file which\n \tshould generate patch file specific \"Cc:\" entries.\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 6dab3bf..3acfdc2 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -70,6 +70,7 @@ git send-email [options] <file | directory | rev-list options >\n \n   Automating:\n     --identity              <str>  * Use the sendemail.<id> options.\n+    --to-cmd                <str>  * Email To: via `<str> \\$patch_path`\n     --cc-cmd                <str>  * Email Cc: via `<str> \\$patch_path`\n     --suppress-cc           <str>  * author, self, sob, cc, cccmd, body, bodycc, all.\n     --[no-]signed-off-by-cc        * Send to Signed-off-by: addresses. Default on.\n@@ -187,7 +188,8 @@ sub do_edit {\n }\n \n # Variables with corresponding config settings\n-my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);\n+my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc);\n+my ($to_cmd, $cc_cmd);\n my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);\n my ($validate, $confirm);\n@@ -214,6 +216,7 @@ my %config_settings = (\n     \"smtppass\" => \\$smtp_authpass,\n \t\"smtpdomain\" => \\$smtp_domain,\n     \"to\" => \\@to,\n+    \"tocmd\" => \\$to_cmd,\n     \"cc\" => \\@initial_cc,\n     \"cccmd\" => \\$cc_cmd,\n     \"aliasfiletype\" => \\$aliasfiletype,\n@@ -272,6 +275,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n                     \"in-reply-to=s\" => \\$initial_reply_to,\n \t\t    \"subject=s\" => \\$initial_subject,\n \t\t    \"to=s\" => \\@to,\n+\t\t    \"to-cmd=s\" => \\$to_cmd,\n \t\t    \"no-to\" => \\$no_to,\n \t\t    \"cc=s\" => \\@initial_cc,\n \t\t    \"no-cc\" => \\$no_cc,\n@@ -711,7 +715,7 @@ if (!defined $sender) {\n \t$prompting++;\n }\n \n-if (!@to) {\n+if (!@to && !defined $to_cmd) {\n \tmy $to = ask(\"Who should the emails be sent to? \");\n \tpush @to, parse_address_line($to) if defined $to; # sanitized/validated later\n \t$prompting++;\n@@ -1238,21 +1242,10 @@ foreach my $t (@files) {\n \t}\n \tclose F;\n \n-\tif (defined $cc_cmd && !$suppress_cc{'cccmd'}) {\n-\t\topen(F, \"$cc_cmd \\Q$t\\E |\")\n-\t\t\tor die \"(cc-cmd) Could not execute '$cc_cmd'\";\n-\t\twhile(<F>) {\n-\t\t\tmy $c = $_;\n-\t\t\t$c =~ s/^\\s*//g;\n-\t\t\t$c =~ s/\\n$//g;\n-\t\t\tnext if ($c eq $sender and $suppress_from);\n-\t\t\tpush @cc, $c;\n-\t\t\tprintf(\"(cc-cmd) Adding cc: %s from: '%s'\\n\",\n-\t\t\t\t$c, $cc_cmd) unless $quiet;\n-\t\t}\n-\t\tclose F\n-\t\t\tor die \"(cc-cmd) failed to close pipe to '$cc_cmd'\";\n-\t}\n+\tpush @to, recipients_cmd(\"to-cmd\", \"to\", $to_cmd, $t)\n+\t\tif defined $to_cmd;\n+\tpush @cc, recipients_cmd(\"cc-cmd\", \"cc\", $cc_cmd, $t)\n+\t\tif defined $cc_cmd && !$suppress_cc{'cccmd'};\n \n \tif ($broken_encoding{$t} && !$has_content_type) {\n \t\t$has_content_type = 1;\n@@ -1310,6 +1303,30 @@ foreach my $t (@files) {\n \t$message_id = undef;\n }\n \n+# Execute a command (ie: $to_cmd) to get a list of email addresses\n+# and return a results array\n+sub recipients_cmd {\n+\tmy ($prefix, $what, $cmd, $file) = @_;\n+\n+\tmy $sanitized_sender = sanitize_address($sender);\n+\tmy @addresses = ();\n+\topen(F, \"$cmd \\Q$file\\E |\")\n+\t    or die \"($prefix) Could not execute '$cmd'\";\n+\twhile(<F>) {\n+\t\tmy $address = $_;\n+\t\t$address =~ s/^\\s*//g;\n+\t\t$address =~ s/\\s*$//g;\n+\t\t$address = sanitize_address($address);\n+\t\tnext if ($address eq $sanitized_sender and $suppress_from);\n+\t\tpush @addresses, $address;\n+\t\tprintf(\"($prefix) Adding %s: %s from: '%s'\\n\",\n+\t\t       $what, $address, $cmd) unless $quiet;\n+\t\t}\n+\tclose F\n+\t    or die \"($prefix) failed to close pipe to '$cmd'\";\n+\treturn @addresses;\n+}\n+\n cleanup_compose_files();\n \n sub cleanup_compose_files() {\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 71b3df9..36cf421 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -201,6 +201,24 @@ test_expect_success $PREREQ 'Prompting works' '\n \t\tgrep \"^To: to@example.com\\$\" msgtxt1\n '\n \n+test_expect_success $PREREQ 'tocmd works' '\n+\tclean_fake_sendmail &&\n+\tcp $patches tocmd.patch &&\n+\techo tocmd--tocmd@example.com >>tocmd.patch &&\n+\t{\n+\t  echo \"#!$SHELL_PATH\"\n+\t  echo sed -n -e s/^tocmd--//p \\\"\\$1\\\"\n+\t} > tocmd-sed &&\n+\tchmod +x tocmd-sed &&\n+\tgit send-email \\\n+\t\t--from=\"Example <nobody@example.com>\" \\\n+\t\t--to-cmd=./tocmd-sed \\\n+\t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\ttocmd.patch \\\n+\t\t&&\n+\tgrep \"^To: tocmd@example.com\" msgtxt1\n+'\n+\n test_expect_success $PREREQ 'cccmd works' '\n \tclean_fake_sendmail &&\n \tcp $patches cccmd.patch &&\n"}]}