summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2024-08-13 17:05:11 -0700
committerJunio C Hamano <gitster@pobox.com>2024-08-17 10:03:06 -0700
commitc038a6f1d748dd1062ffa91f7a8453c73f5bcf9f (patch)
tree2714a6bf636da4b91824202bf6f08812cf71868f /git-send-email.perl
parentbbc04b0094621bdd6d1e60c1cd96c64d916d3339 (diff)
send-email: teach git send-email option to translate aliases
git send-email has support for converting shorthand alias names to canonical email addresses via the alias file. It supports a wide variety of alias file formats based on popular email program file formats. Other programs, such as b4, would like the ability to convert aliases in the same way as git send-email without needing to re-implement the logic for understanding the many file formats. Teach git send-email a new option, --translate-aliases, which will enable this functionality. Similar to --dump-aliases, this option works like a new mode of operation for git send-email. When run with --translate-aliases, git send-email reads from standard input and converts any provided alias into its canonical name and email according to the alias file. Each expanded name and address is printed to standard output, one per line. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl21
1 files changed, 20 insertions, 1 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index 72044e5ef3..cdcee1d0cf 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -31,6 +31,7 @@ sub usage {
git send-email [<options>] <file|directory>
git send-email [<options>] <format-patch options>
git send-email --dump-aliases
+git send-email --translate-aliases
Composing:
--from <str> * Email From:
@@ -99,6 +100,10 @@ git send-email --dump-aliases
Information:
--dump-aliases * Dump configured aliases and exit.
+ --translate-aliases * Translate aliases read from standard
+ input according to the configured email
+ alias file(s), outputting the result to
+ standard output.
EOT
exit(1);
@@ -212,6 +217,7 @@ my $format_patch;
my $compose_filename;
my $force = 0;
my $dump_aliases = 0;
+my $translate_aliases = 0;
# Variables to prevent short format-patch options from being captured
# as abbreviated send-email options
@@ -476,11 +482,14 @@ my $git_completion_helper;
my %dump_aliases_options = (
"h" => \$help,
"dump-aliases" => \$dump_aliases,
+ "translate-aliases" => \$translate_aliases,
);
$rc = GetOptions(%dump_aliases_options);
usage() unless $rc;
die __("--dump-aliases incompatible with other options\n")
- if !$help and $dump_aliases and @ARGV;
+ if !$help and ($dump_aliases or $translate_aliases) and @ARGV;
+die __("--dump-aliases and --translate-aliases are mutually exclusive\n")
+ if !$help and $dump_aliases and $translate_aliases;
my %options = (
"sender|from=s" => \$sender,
"in-reply-to=s" => \$initial_in_reply_to,
@@ -724,6 +733,16 @@ if ($dump_aliases) {
exit(0);
}
+if ($translate_aliases) {
+ while (<STDIN>) {
+ my @addr_list = parse_address_line($_);
+ @addr_list = expand_aliases(@addr_list);
+ @addr_list = sanitize_address_list(@addr_list);
+ print "$_\n" for @addr_list;
+ }
+ exit(0);
+}
+
# is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if
# $f is a revision list specification to be passed to format-patch.
sub is_format_patch_arg {