@@ -40,7 +40,8 @@ package main;
4040
4141sub usage {
4242 print <<EOT ;
43- git send-email [options] <file | directory | rev-list options >
43+ git send-email' [<options>] <file|directory>
44+ git send-email' [<options>] <format-patch options>
4445git send-email --dump-aliases
4546
4647 Composing:
@@ -113,9 +114,38 @@ sub usage {
113114 exit (1);
114115}
115116
117+ sub uniq {
118+ my %seen ;
119+ grep !$seen {$_ }++, @_ ;
120+ }
121+
116122sub completion_helper {
117- print Git::command(' format-patch' , ' --git-completion-helper' );
118- exit (0);
123+ my ($original_opts ) = @_ ;
124+ my %not_for_completion = (
125+ " git-completion-helper" => undef ,
126+ " h" => undef ,
127+ );
128+ my @send_email_opts = ();
129+
130+ foreach my $key (keys %$original_opts ) {
131+ unless (exists $not_for_completion {$key }) {
132+ $key =~ s / !$// ;
133+
134+ if ($key =~ / [:=][si]$ / ) {
135+ $key =~ s / [:=][si]$// ;
136+ push (@send_email_opts , " --$_ =" ) foreach (split (/ \| / , $key ));
137+ } else {
138+ push (@send_email_opts , " --$_ " ) foreach (split (/ \| / , $key ));
139+ }
140+ }
141+ }
142+
143+ my @format_patch_opts = split (/ / , Git::command(' format-patch' , ' --git-completion-helper' ));
144+ my @opts = (@send_email_opts , @format_patch_opts );
145+ @opts = uniq (grep !/^$/ , @opts );
146+ # There's an implicit '\n' here already, no need to add an explicit one.
147+ print " @opts " ;
148+ exit (0);
119149}
120150
121151# most mail servers generate the Date: header, but not all...
@@ -425,10 +455,11 @@ sub config_regexp {
425455 my $key = " sendemail.identity" ;
426456 $identity = Git::config(@repo , $key ) if exists $known_config_keys {$key };
427457}
428- my $rc = GetOptions (
458+ my %identity_options = (
429459 " identity=s" => \$identity ,
430460 " no-identity" => \$no_identity ,
431461);
462+ my $rc = GetOptions(%identity_options );
432463usage() unless $rc ;
433464undef $identity if $no_identity ;
434465
@@ -444,14 +475,17 @@ sub config_regexp {
444475
445476my $help ;
446477my $git_completion_helper ;
447- $rc = GetOptions(" h" => \$help ,
448- " dump-aliases" => \$dump_aliases );
478+ my %dump_aliases_options = (
479+ " h" => \$help ,
480+ " dump-aliases" => \$dump_aliases ,
481+ );
482+ $rc = GetOptions(%dump_aliases_options );
449483usage() unless $rc ;
450484die __(" --dump-aliases incompatible with other options\n " )
451485 if !$help and $dump_aliases and @ARGV ;
452- $rc = GetOptions (
486+ my %options = (
453487 " sender|from=s" => \$sender ,
454- " in-reply-to=s" => \$initial_in_reply_to ,
488+ " in-reply-to=s" => \$initial_in_reply_to ,
455489 " reply-to=s" => \$reply_to ,
456490 " subject=s" => \$initial_subject ,
457491 " to=s" => \@getopt_to ,
@@ -508,15 +542,17 @@ sub config_regexp {
508542 " batch-size=i" => \$batch_size ,
509543 " relogin-delay=i" => \$relogin_delay ,
510544 " git-completion-helper" => \$git_completion_helper ,
511- );
545+ );
546+ $rc = GetOptions(%options );
512547
513548# Munge any "either config or getopt, not both" variables
514549my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to );
515550my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc );
516551my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc );
517552
518553usage() if $help ;
519- completion_helper() if $git_completion_helper ;
554+ my %all_options = (%options , %dump_aliases_options , %identity_options );
555+ completion_helper(\%all_options ) if $git_completion_helper ;
520556unless ($rc ) {
521557 usage();
522558}
0 commit comments