@@ -40,7 +40,8 @@ package main;
40
40
41
41
sub usage {
42
42
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>
44
45
git send-email --dump-aliases
45
46
46
47
Composing:
@@ -113,9 +114,38 @@ sub usage {
113
114
exit (1);
114
115
}
115
116
117
+ sub uniq {
118
+ my %seen ;
119
+ grep !$seen {$_ }++, @_ ;
120
+ }
121
+
116
122
sub 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);
119
149
}
120
150
121
151
# most mail servers generate the Date: header, but not all...
@@ -425,10 +455,11 @@ sub config_regexp {
425
455
my $key = " sendemail.identity" ;
426
456
$identity = Git::config(@repo , $key ) if exists $known_config_keys {$key };
427
457
}
428
- my $rc = GetOptions (
458
+ my %identity_options = (
429
459
" identity=s" => \$identity ,
430
460
" no-identity" => \$no_identity ,
431
461
);
462
+ my $rc = GetOptions(%identity_options );
432
463
usage() unless $rc ;
433
464
undef $identity if $no_identity ;
434
465
@@ -444,14 +475,17 @@ sub config_regexp {
444
475
445
476
my $help ;
446
477
my $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 );
449
483
usage() unless $rc ;
450
484
die __(" --dump-aliases incompatible with other options\n " )
451
485
if !$help and $dump_aliases and @ARGV ;
452
- $rc = GetOptions (
486
+ my %options = (
453
487
" sender|from=s" => \$sender ,
454
- " in-reply-to=s" => \$initial_in_reply_to ,
488
+ " in-reply-to=s" => \$initial_in_reply_to ,
455
489
" reply-to=s" => \$reply_to ,
456
490
" subject=s" => \$initial_subject ,
457
491
" to=s" => \@getopt_to ,
@@ -508,15 +542,17 @@ sub config_regexp {
508
542
" batch-size=i" => \$batch_size ,
509
543
" relogin-delay=i" => \$relogin_delay ,
510
544
" git-completion-helper" => \$git_completion_helper ,
511
- );
545
+ );
546
+ $rc = GetOptions(%options );
512
547
513
548
# Munge any "either config or getopt, not both" variables
514
549
my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to );
515
550
my @initial_cc = @getopt_cc ? @getopt_cc : ($no_cc ? () : @config_cc );
516
551
my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc );
517
552
518
553
usage() 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 ;
520
556
unless ($rc ) {
521
557
usage();
522
558
}
0 commit comments