{"thread":{"id":"61924","subject":"[PATCH 0/3] send-email: teach git send-email mode to translate aliases","startedAt":"2024-08-08T21:10:04Z","lastAt":"2024-08-10T00:29:30Z","messageCount":10,"participants":["Jacob Keller","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"500521","messageId":"20240808-jk-translate-alias-send-email-v1-0-10a03b3d6b06@gmail.com","threadId":"61924","inReplyTo":null,"subject":"[PATCH 0/3] send-email: teach git send-email mode to translate aliases","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-08T21:09:57Z","receivedAt":"2024-08-08T21:10:04Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"The b4 program has its own \"b4 send\" utility for sending a patch series. It\nis similar in many respects to git send-email. Currently, it lacks support\nfor processing aliases, which makes switching between git send-email and b4\nsend somewhat annoying.\n\nIt would be convenient if b4 (or other programs interacting with git) could\nmake use of git send-email's alias file support.\n\nTeach git send-email a new --translate-aliases option, which enables a new\nmode to interpret all remaining arguments as email aliases, translating\nthem according to the configured alias file. Output the translated email\naddresses one per line.\n\nI also considered implementing a new \"full\" format for --dump-aliases which\nwould dump the entire alias file along with its configured email addresses.\nI ended up dropping that change as I felt that it would be less usable than\nthe translation feature.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\nJacob Keller (3):\n      t90001-send-email.sh: fix quoting for mailrc --dump-aliases test\n      t9001-send-email.sh: update alias list used for pine test\n      send-email: teach git send-email option to translate aliases\n\n Documentation/git-send-email.txt |   7 +++\n git-send-email.perl              |  17 ++++++-\n t/t9001-send-email.sh            | 103 ++++++++++++++++++++++++++++++++++++---\n 3 files changed, 120 insertions(+), 7 deletions(-)\n---\nbase-commit: 406f326d271e0bacecdb00425422c5fa3f314930\nchange-id: 20240808-jk-translate-alias-send-email-1ce048643e5d\n\nBest regards,\n-- \nJacob Keller <jacob.keller@gmail.com>\n\n"},{"id":"500522","messageId":"20240808-jk-translate-alias-send-email-v1-1-10a03b3d6b06@gmail.com","threadId":"61924","inReplyTo":"20240808-jk-translate-alias-send-email-v1-0-10a03b3d6b06@gmail.com","subject":"[PATCH 1/3] t90001-send-email.sh: fix quoting for mailrc --dump-aliases test","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-08T21:09:58Z","receivedAt":"2024-08-08T21:10:06Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nThe .mailrc alias file format documents that multiple addresses are\nseparated by spaces. The alias file used in the t9001 --dump-aliases\nmailrc test have addresses which include both a name and email. These\nare unquoted, so git send-email will parse this as an alias that\ntranslates to multiple independent addresses.\n\nThe existing test does not care about this, as --dump-aliases only dumps\nthe alias and not the address. However, it is incorrect for a future\nwhere --dump-aliases could also dump the mail addresses.\n\nFix the test to quote the aliases properly, so that they translate to a\nsingle address.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9001-send-email.sh | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 64a4ab3736ef..aa36ace393b7 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -2084,9 +2084,9 @@ test_dump_aliases '--dump-aliases mailrc format' \\\n \t'bob' \\\n \t'chloe' \\\n \t'eve' <<-\\EOF\n-\talias alice   Alice W Land <awol@example.com>\n-\talias eve     Eve <eve@example.com>\n-\talias bob     Robert Bobbyton <bob@example.com>\n+\talias alice   \"Alice W Land <awol@example.com>\"\n+\talias eve     \"Eve <eve@example.com>\"\n+\talias bob     \"Robert Bobbyton <bob@example.com>\"\n \talias chloe   chloe@example.com\n \tEOF\n \n\n-- \n2.46.0.124.g2dc1a81c8933\n\n"},{"id":"500523","messageId":"20240808-jk-translate-alias-send-email-v1-2-10a03b3d6b06@gmail.com","threadId":"61924","inReplyTo":"20240808-jk-translate-alias-send-email-v1-0-10a03b3d6b06@gmail.com","subject":"[PATCH 2/3] t9001-send-email.sh: update alias list used for pine test","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-08T21:09:59Z","receivedAt":"2024-08-08T21:10:07Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nThe set of aliases used for the pine --dump-aliases test do not\nperfectly mesh with the way the pine address book is defined. While\ntechnically all valid, there are some oddities including bob's name\nbeing partially split so that the actual address is returned as\n\"Bobbyton <bob@example.com\". A strict reading of the pine documentation\nindicates that the address should either be of the form\n\"address@domain\" or a comma separated list of address, name/address\npairs, or other aliases enclosed by ().\n\nThe parsing implementation in git-send-email is not as strict, but it\nmakes sense to ensure the test data used is. Although the --dump-aliases\ntest does not make use of the address data, it is helpful to avoid\ngiving future developers the wrong impression of the file format.\n\nAlso add an alias which translates to multiple addresses using the ()\nformat.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n t/t9001-send-email.sh | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex aa36ace393b7..c96d6955b9f2 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -2093,13 +2093,15 @@ test_dump_aliases '--dump-aliases mailrc format' \\\n test_dump_aliases '--dump-aliases pine format' \\\n \t'pine' \\\n \t'alice' \\\n+\t'bcgrp' \\\n \t'bob' \\\n \t'chloe' \\\n \t'eve' <<-\\EOF\n-\talice\tAlice W Land\t<awol@example.com>\n-\teve\tEve\t<eve@example.com>\n-\tbob\tRobert\tBobbyton <bob@example.com>\n+\talice\tAlice W Land\tawol@example.com\t\tFriend\n+\teve\tEve\teve@example.com\n+\tbob\tRobert Bobbyton\tbob@example.com\n \tchloe\t\tchloe@example.com\n+\tbcgrp\t\t(bob, chloe, Other <o@example.com>)\n \tEOF\n \n test_dump_aliases '--dump-aliases gnus format' \\\n\n-- \n2.46.0.124.g2dc1a81c8933\n\n"},{"id":"500524","messageId":"20240808-jk-translate-alias-send-email-v1-3-10a03b3d6b06@gmail.com","threadId":"61924","inReplyTo":"20240808-jk-translate-alias-send-email-v1-0-10a03b3d6b06@gmail.com","subject":"[PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-08T21:10:00Z","receivedAt":"2024-08-08T21:10:08Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nAdd a new \"--translate-aliases\" option to git send-email which allows\nother programs to convert email aliases according to the configured\nalias file. This is intended to allow b4 send the ability to use the\nsame aliases as git send-email.\n\nThere is one tricky part of handling the new option, since\n--translate-aliases wants to consume the rest of @ARGV. Currently, the\npass_through option is set for perl's Getopt::Long::Configure, which\ncauses unknown options to get passed through to other option parsers.\n\nThis is required in order to handle passing format-patch options, and is\ntricky to work around. --dump-aliases handles this by testing @ARGV\nbefore calling the full option parser. We can't do this with\n--translate-aliases because it wants to consume the arguments.\n\nInstead, skip calling GetOptions a second time of --translate-aliases is\nset. This has the effect that known options will instead be translated\nas aliases instead of producing a warning, but this seems like the best\ntrade off of the available options.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n Documentation/git-send-email.txt |  7 ++++\n git-send-email.perl              | 17 +++++++-\n t/t9001-send-email.sh            | 89 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 112 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex c5d664f4519b..6964c9914a9c 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -12,6 +12,7 @@ SYNOPSIS\n 'git send-email' [<options>] (<file>|<directory>)...\n 'git send-email' [<options>] <format-patch-options>\n 'git send-email' --dump-aliases\n+'git send-email' --translate-aliases (<alias>)...\n \n \n DESCRIPTION\n@@ -475,6 +476,12 @@ Information\n \tthat this only includes the alias name and not its expanded email addresses.\n \tSee 'sendemail.aliasesFile' for more information about aliases.\n \n+--translate-aliases::\n+\tInstead of the normal operation, interpret all command line\n+\targuments as shorthand alias names using the configured alias\n+\tfile(s). Output each translated email address, one per line, in the\n+\torder the aliases appear. See 'sendemail.aliasFile' for more\n+\tinformation about aliases.\n \n CONFIGURATION\n -------------\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 72044e5ef3a8..2ae6cc0d7a36 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -31,6 +31,7 @@ sub usage {\n git send-email [<options>] <file|directory>\n git send-email [<options>] <format-patch options>\n git send-email --dump-aliases\n+git send-email --translate-aliases <alias>\n \n   Composing:\n     --from                  <str>  * Email From:\n@@ -99,6 +100,11 @@ sub usage {\n \n   Information:\n     --dump-aliases                 * Dump configured aliases and exit.\n+    --translate-aliases            * Interpret all other command line arguments\n+                                     as email aliases. Translate them\n+                                     according to the configured alias file,\n+                                     outputing each address one per line, then\n+                                     exit.\n \n EOT\n \texit(1);\n@@ -212,6 +218,7 @@ sub format_2822_time {\n my $compose_filename;\n my $force = 0;\n my $dump_aliases = 0;\n+my $translate_aliases = 0;\n \n # Variables to prevent short format-patch options from being captured\n # as abbreviated send-email options\n@@ -476,11 +483,14 @@ sub config_regexp {\n my %dump_aliases_options = (\n \t\"h\" => \\$help,\n \t\"dump-aliases\" => \\$dump_aliases,\n+\t\"translate-aliases\" => \\$translate_aliases,\n );\n $rc = GetOptions(%dump_aliases_options);\n usage() unless $rc;\n die __(\"--dump-aliases incompatible with other options\\n\")\n     if !$help and $dump_aliases and @ARGV;\n+die __(\"--dump-aliases and --translate-aliases are mutually exclusive\\n\")\n+    if !$help and $dump_aliases and $translate_aliases;\n my %options = (\n \t\t    \"sender|from=s\" => \\$sender,\n \t\t    \"in-reply-to=s\" => \\$initial_in_reply_to,\n@@ -534,7 +544,7 @@ sub config_regexp {\n \t\t    \"git-completion-helper\" => \\$git_completion_helper,\n \t\t    \"v=s\" => \\$reroll_count,\n );\n-$rc = GetOptions(%options);\n+($rc = GetOptions(%options)) unless $translate_aliases;\n \n # Munge any \"either config or getopt, not both\" variables\n my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to);\n@@ -724,6 +734,11 @@ sub parse_sendmail_aliases {\n     exit(0);\n }\n \n+if ($translate_aliases) {\n+\tprint \"$_\\n\" for (process_address_list(@ARGV));\n+\texit(0);\n+}\n+\n # is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if\n # $f is a revision list specification to be passed to format-patch.\n sub is_format_patch_arg {\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex c96d6955b9f2..78c451918145 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -2120,6 +2120,95 @@ test_expect_success '--dump-aliases must be used alone' '\n \ttest_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting\n '\n \n+test_translate_aliases () {\n+\tmsg=\"$1\" && shift &&\n+\tfiletype=\"$1\" && shift &&\n+\taliases=\"$1\" && shift &&\n+\tprintf '%s\\n' \"$@\" >expect &&\n+\tcat >.tmp-email-aliases &&\n+\n+\ttest_expect_success $PREREQ \"$msg\" '\n+\t\tclean_fake_sendmail && rm -fr outdir &&\n+\t\tgit config --replace-all sendemail.aliasesfile \\\n+\t\t\t\"$(pwd)/.tmp-email-aliases\" &&\n+\t\tgit config sendemail.aliasfiletype \"$filetype\" &&\n+\t\tgit send-email --translate-aliases $aliases 2>errors >actual &&\n+\t\ttest_cmp expect actual\n+\t'\n+}\n+\n+test_translate_aliases '--translate-aliases sendmail format' \\\n+\t'sendmail' \\\n+\t'alice bcgrp' \\\n+\t'Alice W Land <awol@example.com>' \\\n+\t'Robert Bobbyton <bob@example.com>' \\\n+\t'chloe@example.com' \\\n+\t'Other <o@example.com>' <<-\\EOF\n+\talice: Alice W Land <awol@example.com>\n+\tbob: Robert Bobbyton <bob@example.com>\n+\tchloe: chloe@example.com\n+\tabgroup: alice, bob\n+\tbcgrp: bob, chloe, Other <o@example.com>\n+\tEOF\n+\n+test_translate_aliases '--translate-aliases mutt format' \\\n+\t'mutt' \\\n+\t'donald bob' \\\n+\t'Donald C Carlton <donc@example.com>' \\\n+\t'Robert Bobbyton <bob@example.com>' <<-\\EOF\n+\talias alice Alice W Land <awol@example.com>\n+\talias donald Donald C Carlton <donc@example.com>\n+\talias bob Robert Bobbyton <bob@example.com>\n+\talias chloe chloe@example.com\n+\tEOF\n+\n+test_translate_aliases '--translate-aliases mailrc format' \\\n+\t'mailrc' \\\n+\t'chloe eve alice' \\\n+\t'chloe@example.com' \\\n+\t'Eve <eve@example.com>' \\\n+\t'Alice W Land <awol@example.com>' <<-\\EOF\n+\talias alice   \"Alice W Land <awol@example.com>\"\n+\talias eve     \"Eve <eve@example.com>\"\n+\talias bob     \"Robert Bobbyton <bob@example.com>\"\n+\talias chloe   chloe@example.com\n+\tEOF\n+\n+test_translate_aliases '--translate-aliases pine format' \\\n+\t'pine' \\\n+\t'eve bob bcgrp' \\\n+\t'eve@example.com' \\\n+\t'bob@example.com' \\\n+\t'bob@example.com' \\\n+\t'chloe@example.com' \\\n+\t'Other <o@example.com>' <<-\\EOF\n+\talice\tAlice W Land\tawol@example.com\t\tFriend\n+\teve\tEve\teve@example.com\n+\tbob\tRobert Bobbyton\tbob@example.com\n+\tchloe\t\tchloe@example.com\n+\tbcgrp\t\t(bob, chloe, Other <o@example.com>)\n+\tEOF\n+\n+test_translate_aliases '--translate-aliases gnus format' \\\n+\t'gnus' \\\n+\t'alice chloe eve' \\\n+\t'awol@example.com' \\\n+\t'chloe@example.com' \\\n+\t'eve@example.com' <<-\\EOF\n+\t(define-mail-alias \"alice\" \"awol@example.com\")\n+\t(define-mail-alias \"eve\" \"eve@example.com\")\n+\t(define-mail-alias \"bob\" \"bob@example.com\")\n+\t(define-mail-alias \"chloe\" \"chloe@example.com\")\n+\tEOF\n+\n+test_expect_success '--translate-aliases passes unknown aliases through' '\n+\tcat >expect <<-\\EOF &&\n+\tOther <o@example.com>\n+\tEOF\n+\tgit send-email --translate-aliases \"Other <o@example.com>\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success $PREREQ 'aliases and sendemail.identity' '\n \ttest_must_fail git \\\n \t\t-c sendemail.identity=cloud \\\n\n-- \n2.46.0.124.g2dc1a81c8933\n\n"},{"id":"500527","messageId":"xmqqttfufzkj.fsf@gitster.g","threadId":"61924","inReplyTo":"20240808-jk-translate-alias-send-email-v1-3-10a03b3d6b06@gmail.com","subject":"Re: [PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-08T21:57:00Z","receivedAt":"2024-08-08T21:57:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.e.keller@intel.com> writes:\n\n> From: Jacob Keller <jacob.keller@gmail.com>\n>\n> Add a new \"--translate-aliases\" option to git send-email which allows\n\nIf you add a thing, it by definition is new, isn't it?\n\n> Instead, skip calling GetOptions a second time of --translate-aliases is\n\n\"of\"???  \"if\" perhaps?\n\n> set. This has the effect that known options will instead be translated\n> as aliases instead of producing a warning, but this seems like the best\n> trade off of the available options.\n\nHmph, I do not quite get why you need such a hack (to be honest, I\ndo not quite understand why dump-aliases needs a similar hack,\neither, even though I do understand why identity thing needs a\nspecial caseing).\n\nAfter GetOptions() returns, usuall we process everything remaining\non the command line as files that contain messages, right?  But\nbefore that happens (i.e. anywhere before the while () loop that\nprocesses elements in @ARGV), you can check if your new option was\ngiven, and if so you can map contents of @ARGV using %aliases and\nexit, and you are done, no?  Bonus point if you make sure that no\nother options were given, but perhaps there are some strange folks\nwho want to use \"--to=fu\" as an e-mail alias, so instead of\ncomplaining that \"--translate\" does not mix with any other options\nwhen \"git send-email --translate --to=fu\" was run, giving alias\ntranslation for \"--to=fu\" may be a better behaviour for those users\nanyway ;-).\n\n"},{"id":"500559","messageId":"328fb497-d16e-4af1-a816-7b4aeb531504@intel.com","threadId":"61924","inReplyTo":"xmqqttfufzkj.fsf@gitster.g","subject":"Re: [PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-09T19:12:34Z","receivedAt":"2024-08-09T19:12:39Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"\n\nOn 8/8/2024 2:57 PM, Junio C Hamano wrote:\n> Jacob Keller <jacob.e.keller@intel.com> writes:\n> \n>> From: Jacob Keller <jacob.keller@gmail.com>\n>>\n>> Add a new \"--translate-aliases\" option to git send-email which allows\n> \n> If you add a thing, it by definition is new, isn't it?\n> \n\nSure.\n\n>> Instead, skip calling GetOptions a second time of --translate-aliases is\n> \n> \"of\"???  \"if\" perhaps?\n>\n\nYep, a typo.\n\n\n>> set. This has the effect that known options will instead be translated\n>> as aliases instead of producing a warning, but this seems like the best\n>> trade off of the available options.\n> \n> Hmph, I do not quite get why you need such a hack (to be honest, I\n> do not quite understand why dump-aliases needs a similar hack,\n> either, even though I do understand why identity thing needs a\n> special caseing).\n> \n\n\nThe problem is that we have pass_through set in the\nGetOpt::Long::Configure. This is necessary because we want to pass the\noptions we don't understand into git format-patch.\n\nBut --dump-aliases and --translate-aliases both do not want to work with\nany other option. If we put these into the main get options, then the\noptions will be interpreted normally and we then have to specially check\nevery single option to make sure nothing else was provided.\n\nDump aliases handled this by checking @ARGV and immediately bailing if\nthere were anything remaining after the call to parsing its inner\noptions. This works but does not work for --translate-aliases because it\nneeds to treat all the remaining arguments as aliases.\n\n> After GetOptions() returns, usuall we process everything remaining\n> on the command line as files that contain messages, right?  But\n> before that happens (i.e. anywhere before the while () loop that\n> processes elements in @ARGV), you can check if your new option was\n> given, and if so you can map contents of @ARGV using %aliases and\n> exit, and you are done, no?  Bonus point if you make sure that no\n> other options were given, but perhaps there are some strange folks\n> who want to use \"--to=fu\" as an e-mail alias, so instead of\n> complaining that \"--translate\" does not mix with any other options\n> when \"git send-email --translate --to=fu\" was run, giving alias\n> translation for \"--to=fu\" may be a better behaviour for those users\n> anyway ;-).\n> \n\nI don't think thats right. We want both --dump-aliases and\n--translate-aliases to reject \"--to\" ideally.\n\nI didn't come up with the best way to handle that yet, as currently:\n\n $ git send-email --translate-aliases --to unknown-alias\n --to\n unknown-alias\n\nI did try turning off option pass_through for the first round of get\noptions, but that also seems to not work properly. I can investigate\nthat route and see if I can get it to behave properly. I think we could\ndrop some special casing.\n\nEssentially, we want to avoid parsing any other options entirely,\nbecause they aren't compatible with --dump-aliases or --translate-aliases.\n"},{"id":"500562","messageId":"xmqq7ccpcx9e.fsf@gitster.g","threadId":"61924","inReplyTo":"328fb497-d16e-4af1-a816-7b4aeb531504@intel.com","subject":"Re: [PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-09T19:27:25Z","receivedAt":"2024-08-09T19:27:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.e.keller@intel.com> writes:\n\n> Dump aliases handled this by checking @ARGV and immediately bailing if\n> there were anything remaining after the call to parsing its inner\n> options. This works but does not work for --translate-aliases because it\n> needs to treat all the remaining arguments as aliases.\n\nWhen GetOptions returns, shouldn't these \"remaining arguments\" be\nvisible in @ARGV and you can iterate over them yourself, perhaps?\n"},{"id":"500567","messageId":"5ad39a07-a2d4-45d2-9b5d-0180cb903801@intel.com","threadId":"61924","inReplyTo":"xmqq7ccpcx9e.fsf@gitster.g","subject":"Re: [PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-09T19:51:45Z","receivedAt":"2024-08-09T19:51:51Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"\n\nOn 8/9/2024 12:27 PM, Junio C Hamano wrote:\n> Jacob Keller <jacob.e.keller@intel.com> writes:\n> \n>> Dump aliases handled this by checking @ARGV and immediately bailing if\n>> there were anything remaining after the call to parsing its inner\n>> options. This works but does not work for --translate-aliases because it\n>> needs to treat all the remaining arguments as aliases.\n> \n> When GetOptions returns, shouldn't these \"remaining arguments\" be\n> visible in @ARGV and you can iterate over them yourself, perhaps?\n\nYes, that is essentially what we do by skipping the call to the\nGetOptions for the main set of send-email options :)\n\nWe still need to go farther down the program in order to call the\nfunctions which parse the alias file and setup the alias map.\n\nI guess we could re-arrange the code so that the alias bits are handled\nbefore the options?\n\nWe also probably want to reject other option-like arguments which\nideally we would have GetOpt::Long handle for us... I think if we\ndisable pass_through initially in the identity/information options and\nthen re-enable it when we call the second GetOptions that might work?\nThat could get tricky...\n\nWe could try to implement scanning for options ourselves, but I wouldn't\nwant to break things like \"--\" to make it treat potential option-looking\nfields as aliases...\n\nOr we could completely change the overall behavior to do something else\nlike take the aliases on standard input instead of the arguments?\n"},{"id":"500573","messageId":"xmqqplqhbe4o.fsf@gitster.g","threadId":"61924","inReplyTo":"5ad39a07-a2d4-45d2-9b5d-0180cb903801@intel.com","subject":"Re: [PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-08-09T21:05:59Z","receivedAt":"2024-08-09T21:06:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.e.keller@intel.com> writes:\n\n> We could try to implement scanning for options ourselves, but I wouldn't\n> want to break things like \"--\" to make it treat potential option-looking\n> fields as aliases...\n\nThe appoach --dump-aliases takes is already broken with respect to\noptions that take or do not take an argument, if you really want to\nscan, understand, and skip irrelevant options anyway, no?  The\nseparate, trimmed down %dump_aliases_options map cannot help you to\ntell from the command line \"git cmd --translate --foo bar\" if\nskipping just \"--foo\" gives you the alias-to-be-expanded \"bar\", or\n\"--foo\" takes an argument that is \"bar\" and there is no alias left.\n\nSo I do not quite know how involved you want to go, but naïvely, I\nwould have thought something along the lines of illustration below\nis sufficient.\n\n git-send-email.perl | 14 ++++++++++++++\n 1 file changed, 14 insertions(+)\n\ndiff --git c/git-send-email.perl w/git-send-email.perl\nindex 72044e5ef3..a7239698f8 100755\n--- c/git-send-email.perl\n+++ w/git-send-email.perl\n@@ -747,6 +747,20 @@ sub is_format_patch_arg {\n \t}\n }\n \n+# Now, if the user who wants --translate knows that the command will not\n+# send any mails and the remainder of the command line are aliases to be\n+# expanded, the user wouldn't have given useless other options to trigger\n+# any of the executable code before this point (like $suppress_cc{} handling)\n+# that would be wasted.  So we just see if --translate is given and deal\n+# with it here.\n+\n+if ($translate_alias) {\n+\tfor (@ARGV) {\n+\t\tprint \"$_ => $aliases{$_}\\n\";\n+\t}\n+\texit(0);\n+}\n+\n # Now that all the defaults are set, process the rest of the command line\n # arguments and collect up the files that need to be processed.\n my @rev_list_opts;\n"},{"id":"500592","messageId":"7f6d556c-c1fe-4a6f-be6f-106f2e0bca48@intel.com","threadId":"61924","inReplyTo":"xmqqplqhbe4o.fsf@gitster.g","subject":"Re: [PATCH 3/3] send-email: teach git send-email option to translate aliases","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2024-08-10T00:29:22Z","receivedAt":"2024-08-10T00:29:30Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"\n\nOn 8/9/2024 2:05 PM, Junio C Hamano wrote:\n> Jacob Keller <jacob.e.keller@intel.com> writes:\n> \n>> We could try to implement scanning for options ourselves, but I wouldn't\n>> want to break things like \"--\" to make it treat potential option-looking\n>> fields as aliases...\n> \n> The appoach --dump-aliases takes is already broken with respect to\n> options that take or do not take an argument, if you really want to\n> scan, understand, and skip irrelevant options anyway, no?  The\n> separate, trimmed down %dump_aliases_options map cannot help you to\n> tell from the command line \"git cmd --translate --foo bar\" if\n> skipping just \"--foo\" gives you the alias-to-be-expanded \"bar\", or\n> \"--foo\" takes an argument that is \"bar\" and there is no alias left.\n> \n\nThe approach --dump-aliases takes is that *any* other command line\nargument besides --dump-aliases will cause git send-email to exit with\nan error. They are not interpreted.\n\nThe approach I had --translate-aliases take is that all other command\nline arguments are treated as aliases, regardless of whether they are\npossibly options, and no other options are parsed at all.\n\nIt is intended that --dump-aliases, --translate-aliases, and the regular\nmode of operation are mutually exclusive.\n\nI am leaning towards possibly making --translate-aliases take the\naliases to translate on stdin instead of using arguments at all. This\nwould make it function more like --dump-aliases w.r.t. command line\narguments. This is probably a lot simpler. I think I will implement it\nthis way for v2.\n\nAlternatively, we could extract the logic for handling the aliases into\na separate script with its own git command, but I think it currently\nrelies heavily on some perl code that would be hard to translate to C.\n\n"}]}