113
exit(1);
114
}
115
116
+sub uniq {
117
+ my %seen;
118
+ grep !$seen{$_}++, @_;
119
+}
120
+
121
sub completion_helper {
117
- print Git::command('format-patch', '--git-completion-helper');
118
- exit(0);
122
+ my ($original_opts) = @_;
123
+ my %not_for_completion = (
124
+ "git-completion-helper" => undef,
125
+ "h" => undef,
126
+ );
127
+ my @send_email_opts = ();
128
+
129
+ foreach my $key (keys %$original_opts) {
130
+ unless (exists $not_for_completion{$key}) {
131
+ $key =~ s/!$//;
132
+
133
+ if ($key =~ /[:=][si]$/) {
134
+ $key =~ s/[:=][si]$//;
135
+ push (@send_email_opts, "--$_=") foreach (split (/\|/, $key));
136
+ } else {
137
+ push (@send_email_opts, "--$_") foreach (split (/\|/, $key));
138
+ }
139
+ }
140
+ }
141
+
142
+ my @format_patch_opts = split(/ /, Git::command('format-patch', '--git-completion-helper'));
143
+ my @opts = (@send_email_opts, @format_patch_opts);
144
+ @opts = uniq (grep !/^$/, @opts);
145
+ # There's an implicit '\n' here already, no need to add an explicit one.
146
+ print "@opts";
147
+ exit(0);
148
}
149
150
# most mail servers generate the Date: header, but not all...
454
my $key = "sendemail.identity";
455
$identity = Git::config(@repo, $key) if exists $known_config_keys{$key};
456
}
428
-my $rc = GetOptions(
457
+my %identity_options = (
458
"identity=s" => \$identity,
459
"no-identity" => \$no_identity,
460
);
461
+my $rc = GetOptions(%identity_options);
462
usage() unless $rc;
463
undef $identity if $no_identity;
464
474
475
my $help;
476
my $git_completion_helper;
447
-$rc = GetOptions("h" => \$help,
448
- "dump-aliases" => \$dump_aliases);
477
+my %dump_aliases_options = (
478
+ "h" => \$help,
479
+ "dump-aliases" => \$dump_aliases,
480
+);
481
+$rc = GetOptions(%dump_aliases_options);
482
usage() unless $rc;
483
die __("--dump-aliases incompatible with other options\n")
484
if !$help and $dump_aliases and @ARGV;
452
-$rc = GetOptions(
485
+my %options = (
486
"sender|from=s" => \$sender,
454
- "in-reply-to=s" => \$initial_in_reply_to,
487
+ "in-reply-to=s" => \$initial_in_reply_to,
488
"reply-to=s" => \$reply_to,
489
"subject=s" => \$initial_subject,
490
"to=s" => \@getopt_to,
541
"batch-size=i" => \$batch_size,
542
"relogin-delay=i" => \$relogin_delay,
543
"git-completion-helper" => \$git_completion_helper,
511
- );
544
+);
545
+$rc = GetOptions(%options);
546
547
# Munge any "either config or getopt, not both" variables
548
my @initial_to = @getopt_to ? @getopt_to : ($no_to ? () : @config_to);
550
my @initial_bcc = @getopt_bcc ? @getopt_bcc : ($no_bcc ? () : @config_bcc);
551
552
usage() if $help;
519
-completion_helper() if $git_completion_helper;
553
+my %all_options = (%options, %dump_aliases_options, %identity_options);
554
+completion_helper(\%all_options) if $git_completion_helper;
555
unless ($rc) {
556
usage();
557
}