Skip to content

Commit 1337498

Browse files
pcloudsgitster
authored andcommitted
completion: use __gitcomp_builtin for format-patch
This helps format-patch gain completion for a couple new options, notably --range-diff. Since send-email completion relies on $__git_format_patch_options which is now reduced, we need to do something not to regress send-email completion. The workaround here is implement --git-completion-helper in send-email.perl just as a bridge to "format-patch --git-completion-helper". This is enough to use __gitcomp_builtin on send-email (to take advantage of caching). In the end, send-email.perl can probably reuse the same info it passes to GetOptions() to generate full --git-completion-helper output so that we don't need to keep track of its options in git-completion.bash anymore. But that's something for another boring day. Helped-by: Denton Liu <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c4df23f commit 1337498

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

contrib/completion/git-completion.bash

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,13 +1532,9 @@ _git_fetch ()
15321532
__git_complete_remote_or_refspec
15331533
}
15341534

1535-
__git_format_patch_options="
1536-
--stdout --attach --no-attach --thread --thread= --no-thread
1537-
--numbered --start-number --numbered-files --keep-subject --signoff
1538-
--signature --no-signature --in-reply-to= --cc= --full-index --binary
1539-
--not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1540-
--inline --suffix= --ignore-if-in-upstream --subject-prefix=
1541-
--output-directory --reroll-count --to= --quiet --notes
1535+
__git_format_patch_extra_options="
1536+
--full-index --not --all --no-prefix --src-prefix=
1537+
--dst-prefix= --notes
15421538
"
15431539

15441540
_git_format_patch ()
@@ -1551,7 +1547,7 @@ _git_format_patch ()
15511547
return
15521548
;;
15531549
--*)
1554-
__gitcomp "$__git_format_patch_options"
1550+
__gitcomp_builtin format-patch "$__git_format_patch_extra_options"
15551551
return
15561552
;;
15571553
esac
@@ -2081,7 +2077,7 @@ _git_send_email ()
20812077
return
20822078
;;
20832079
--*)
2084-
__gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2080+
__gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
20852081
--compose --confirm= --dry-run --envelope-sender
20862082
--from --identity
20872083
--in-reply-to --no-chain-reply-to --no-signed-off-by-cc
@@ -2090,7 +2086,7 @@ _git_send_email ()
20902086
--smtp-server-port --smtp-encryption= --smtp-user
20912087
--subject --suppress-cc= --suppress-from --thread --to
20922088
--validate --no-validate
2093-
$__git_format_patch_options"
2089+
$__git_format_patch_extra_options"
20942090
return
20952091
;;
20962092
esac

git-send-email.perl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ sub usage {
119119
exit(1);
120120
}
121121

122+
sub completion_helper {
123+
print Git::command('format-patch', '--git-completion-helper');
124+
exit(0);
125+
}
126+
122127
# most mail servers generate the Date: header, but not all...
123128
sub format_2822_time {
124129
my ($time) = @_;
@@ -311,6 +316,7 @@ sub signal_handler {
311316
# needing, first, from the command line:
312317

313318
my $help;
319+
my $git_completion_helper;
314320
my $rc = GetOptions("h" => \$help,
315321
"dump-aliases" => \$dump_aliases);
316322
usage() unless $rc;
@@ -373,9 +379,11 @@ sub signal_handler {
373379
"no-xmailer" => sub {$use_xmailer = 0},
374380
"batch-size=i" => \$batch_size,
375381
"relogin-delay=i" => \$relogin_delay,
382+
"git-completion-helper" => \$git_completion_helper,
376383
);
377384

378385
usage() if $help;
386+
completion_helper() if $git_completion_helper;
379387
unless ($rc) {
380388
usage();
381389
}

0 commit comments

Comments
 (0)