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 <liu.denton@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Duy Nguyen committed Nov 3, 2018 at 07:03 UTC 13374987dd889858758afef458bd8a8cbf15bb4d
2 files changed +14 -10
contrib/completion/git-completion.bash
+6 -10
@@ -1532,13 +1532,9 @@ _git_fetch ()
1532 __git_complete_remote_or_refspec
1533 }
1534
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
1538 "
1539
1540 _git_format_patch ()
@@ -1551,7 +1547,7 @@ _git_format_patch ()
1547 return
1548 ;;
1549 --*)
1554 - __gitcomp "$__git_format_patch_options"
1550 + __gitcomp_builtin format-patch "$__git_format_patch_extra_options"
1551 return
1552 ;;
1553 esac
@@ -2081,7 +2077,7 @@ _git_send_email ()
2077 return
2078 ;;
2079 --*)
2084 - __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
2080 + __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
2081 --compose --confirm= --dry-run --envelope-sender
2082 --from --identity
2083 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
@@ -2090,7 +2086,7 @@ _git_send_email ()
2086 --smtp-server-port --smtp-encryption= --smtp-user
2087 --subject --suppress-cc= --suppress-from --thread --to
2088 --validate --no-validate
2093 - $__git_format_patch_options"
2089 + $__git_format_patch_extra_options"
2090 return
2091 ;;
2092 esac
git-send-email.perl
+8
@@ -119,6 +119,11 @@ EOT
119 exit(1);
120 }
121
122 +sub completion_helper {
123 + print Git::command('format-patch', '--git-completion-helper');
124 + exit(0);
125 +}
126 +
127 # most mail servers generate the Date: header, but not all...
128 sub format_2822_time {
129 my ($time) = @_;
@@ -311,6 +316,7 @@ $SIG{INT} = \&signal_handler;
316 # needing, first, from the command line:
317
318 my $help;
319 +my $git_completion_helper;
320 my $rc = GetOptions("h" => \$help,
321 "dump-aliases" => \$dump_aliases);
322 usage() unless $rc;
@@ -373,9 +379,11 @@ $rc = GetOptions(
379 "no-xmailer" => sub {$use_xmailer = 0},
380 "batch-size=i" => \$batch_size,
381 "relogin-delay=i" => \$relogin_delay,
382 + "git-completion-helper" => \$git_completion_helper,
383 );
384
385 usage() if $help;
386 +completion_helper() if $git_completion_helper;
387 unless ($rc) {
388 usage();
389 }