nd/parseopt-completion fixups
cover nd/parseopt-completion fixups
This addresses some comments from v3 [1]. Since the series has been merged to 'next', we do incremental updates instead:
- --rerere-autoupdate is completable on am, revert and cherry-pick
- simplification in _git_notes which leads to completion in 'git notes remove'
[1] https://public-inbox.org/git/[email protected]/
Nguyễn Thái Ngọc Duy (2):
completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate
completion: simplify _git_notes
contrib/completion/git-completion.bash | 18 +++--------------- parse-options.h | 4 ++-- rerere.h | 3 +-- 3 files changed, 6 insertions(+), 19 deletions(-)
Signature · 1 line
2.16.1.435.g8f24da2e1a
PATCH 1/2 completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate
There is not a strong reason to hide this option, and git-merge already completes this one. Let's allow to complete this for all commands (and let git-completion.bash do the suppressing if neede).
This makes --rerere-autoupdate completable for am, cherry-pick and revert.
--- contrib/completion/git-completion.bash | 3 +-- parse-options.h | 4 ++-- rerere.h | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-)
contrib/completion/git-completion.bash +1 -2
@@ -1754,8 +1754,7 @@ _git_merge () case "$cur" in --*) - __gitcomp_builtin merge "--rerere-autoupdate - --no-rerere-autoupdate + __gitcomp_builtin merge "--no-rerere-autoupdate --no-commit --no-edit --no-ff --no-log --no-progress --no-squash --no-stat
parse-options.h +2 -2
@@ -148,8 +148,8 @@ struct option {#define OPT_STRING_LIST (s, l, v, a, h) \ { OPTION_CALLBACK, (s), (l), (v), (a), \ (h), 0, &parse_opt_string_list } -#define OPT_UYN (s, l, v, h, f) { OPTION_CALLBACK, (s), (l), (v), NULL, \ - (h), PARSE_OPT_NOARG|(f), &parse_opt_tertiary } +#define OPT_UYN (s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, &parse_opt_tertiary }#define OPT_DATE (s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \ parse_opt_approxidate_cb }
rerere.h +1 -2
@@ -37,7 +37,6 @@ extern void rerere_clear(struct string_list *);extern void rerere_gc (struct string_list *);#define OPT_RERERE_AUTOUPDATE (v) OPT_UYN(0, "rerere-autoupdate", (v), \ - N_("update the index with reused conflict resolution if possible"), \ - PARSE_OPT_NOCOMPLETE) + N_("update the index with reused conflict resolution if possible"))#endif
Signature · 1 line
2.16.1.435.g8f24da2e1a
PATCH 2/2 completion: simplify _git_notes
In reply to Nguyễn Thái Ngọc DuyThis also adds completion for 'git notes remove' with two options:
--ignore-missing and --stdin.
For some strange reason, 'git notes undefined --<tab>' completes --ref without even running --git-completion-helper. But since this is an error case (and we're not doing anything destructive, it's probably ok for now)
--- contrib/completion/git-completion.bash | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
contrib/completion/git-completion.bash +2 -13
@@ -1836,19 +1836,8 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; - add,--*) - __gitcomp_builtin notes_add - ;; - append,--*) - __gitcomp_builtin notes_append - ;; - copy,--*) - __gitcomp_builtin notes_copy - ;; - prune,--*) - __gitcomp_builtin notes_prune - ;; - prune,*) + *,--*) + __gitcomp_builtin notes_$subcommand ;; *) case "$prev" in
Signature · 1 line
2.16.1.435.g8f24da2e1a
Re: [PATCH 1/2] completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate
In reply to Nguyễn Thái Ngọc DuyQuoted 3 lines · Nguyễn Thái Ngọc Duy
There is not a strong reason to hide this option, and git-merge already completes this one. Let's allow to complete this for all commands (and let git-completion.bash do the suppressing if neede).
s/neede/needed/
Quoted 4 lines
This makes --rerere-autoupdate completable for am, cherry-pick and revert.
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>
Re: [PATCH 2/2] completion: simplify _git_notes
In reply to Nguyễn Thái Ngọc DuyQuoted 5 lines · Nguyễn Thái Ngọc Duy
This also adds completion for 'git notes remove' with two options:
--ignore-missing and --stdin.For some strange reason, 'git notes undefined --<tab>' completes --ref without even running --git-completion-helper.
There is nothing strange about it. _git_notes() first looks for the presence of any subcommands on the command line, and if it doesn't find any, it will list 'git notes's subcommands and options for completion. And it does so by running '__gitcomp "$subcommands --ref"'
Quoted 2 lines
But since this is an error
case (and we're not doing anything destructive, it's probably ok for now)
I agree; and it matches the behaviour before the patch.
Quoted 34 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- contrib/completion/git-completion.bash | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)contrib/completion/git-completion.bash +2
-14@@ -1836,19 +1836,8 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; - add,--*) - __gitcomp_builtin notes_add - ;; - append,--*) - __gitcomp_builtin notes_append - ;; - copy,--*) - __gitcomp_builtin notes_copy - ;; - prune,--*) - __gitcomp_builtin notes_prune - ;; - prune,*) + *,--*) + __gitcomp_builtin notes_$subcommand ;; *) case "$prev" in --2.16.1.435.g8f24da2e1a
Re: [PATCH 2/2] completion: simplify _git_notes
In reply to Nguyễn Thái Ngọc DuyQuoted 23 lines · Nguyễn Thái Ngọc Duy
This also adds completion for 'git notes remove' with two options:
--ignore-missing and --stdin.For some strange reason, 'git notes undefined --<tab>' completes --ref without even running --git-completion-helper. But since this is an error case (and we're not doing anything destructive, it's probably ok for now)
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- contrib/completion/git-completion.bash | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)contrib/completion/git-completion.bash +0
-3@@ -1836,19 +1836,8 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; - add,--*) - __gitcomp_builtin notes_add - ;;
contrib/completion/git-completion.bash _git_notes () · line 1851
Quoted 10 lines
contrib/completion/git-completion.bash +0
-10- append,--*) - __gitcomp_builtin notes_append - ;; - copy,--*) - __gitcomp_builtin notes_copy - ;; - prune,--*) - __gitcomp_builtin notes_prune - ;; - prune,*)
There is a minor behaviour change here, though. This
prune,*)
;;
case arm ensured that we don't list refs for 'git notes prune <TAB>', because it doesn't accept them (and then we take our usual fallback and let Bash complete filenames; yeah, 'git notes prune' doesn't accept filenames either, but, as I said, that's our usual fallback when we can't offer anything for completion).
This patch removes that case arm, and refs will be offered for 'git notes prune <TAB>'.
Quoted 8 lines
contrib/completion/git-completion.bash +2
-1+ *,--*) + __gitcomp_builtin notes_$subcommand ;; *) case "$prev" in --2.16.1.435.g8f24da2e1a
Re: [PATCH 1/2] completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate
In reply to Nguyễn Thái Ngọc DuyQuoted 8 lines · Nguyễn Thái Ngọc Duy
There is not a strong reason to hide this option, and git-merge already completes this one. Let's allow to complete this for all commands (and let git-completion.bash do the suppressing if neede).
This makes --rerere-autoupdate completable for am, cherry-pick and revert.
This is slightly off topic as it doesn't use OPT_RERERE_AUTOUPDATE but it looks[1] as if rebase is missing completion for --rerere-autoupdate (and --signoff which is definitely off topic)
Best Wishes
Phillip
[1]
https://git.kernel.org/pub/scm/git/git.git/tree/contrib/completion/git-completion.bash#n2010
Quoted 50 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- contrib/completion/git-completion.bash | 3 +-- parse-options.h | 4 ++-- rerere.h | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-)contrib/completion/git-completion.bash +1
-2@@ -1754,8 +1754,7 @@ _git_merge () case "$cur" in --*) - __gitcomp_builtin merge "--rerere-autoupdate - --no-rerere-autoupdate + __gitcomp_builtin merge "--no-rerere-autoupdate --no-commit --no-edit --no-ff --no-log --no-progress --no-squash --no-statparse-options.h +2
-2@@ -148,8 +148,8 @@ struct option {#define OPT_STRING_LIST (s, l, v, a, h) \ { OPTION_CALLBACK, (s), (l), (v), (a), \ (h), 0, &parse_opt_string_list } -#define OPT_UYN (s, l, v, h, f) { OPTION_CALLBACK, (s), (l), (v), NULL, \ - (h), PARSE_OPT_NOARG|(f), &parse_opt_tertiary } +#define OPT_UYN (s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, &parse_opt_tertiary }#define OPT_DATE (s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \ parse_opt_approxidate_cb }rerere.h +1
-2@@ -37,7 +37,6 @@ extern void rerere_clear(struct string_list *);extern void rerere_gc (struct string_list *);#define OPT_RERERE_AUTOUPDATE (v) OPT_UYN(0, "rerere-autoupdate", (v), \ - N_("update the index with reused conflict resolution if possible"), \ - PARSE_OPT_NOCOMPLETE) + N_("update the index with reused conflict resolution if possible"))#endif
Re: [PATCH 2/2] completion: simplify _git_notes
In reply to SZEDER GáborQuoted 5 lines · SZEDER Gábor
There is a minor behaviour change here, though. This
prune,*)
;;
Quoted 14 lines
case arm ensured that we don't list refs for 'git notes prune <TAB>', because it doesn't accept them (and then we take our usual fallback and let Bash complete filenames; yeah, 'git notes prune' doesn't accept filenames either, but, as I said, that's our usual fallback when we can't offer anything for completion).
This patch removes that case arm, and refs will be offered for 'git notes prune <TAB>'.
Quoted 5 lines
(quoted diff) +2
-0+ *,--*) + __gitcomp_builtin notes_$subcommand ;; *) case "$prev" in
I have this tentatively queued on the topic. Can we wrap the topic up and move it forward, instead of leaving it (and other topics) hanging around and causing conflicts with other topics in flight, please?
Thanks.
Subject: [PATCH] SQUASH???
By Szeder <CAM0VKjmmF2t=B2s3rJoKmO3j6Bk5d6PEfCV==ONRGMcdUMLFpQ@mail.gmail.com>
--- contrib/completion/git-completion.bash | 5 +++++ 1 file changed, 5 insertions(+)
contrib/completion/git-completion.bash +5 -0
@@ -1836,6 +1836,11 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; + prune,--*) + __gitcomp_builtin notes_prune + ;; + prune,*) + ;; *,--*) __gitcomp_builtin notes_$subcommand ;;
Signature · 1 line
2.16.2-345-g7e31236f65
v2 cover nd/parseopt-completion fixups
In reply to Nguyễn Thái Ngọc Duyv2 fixes the comments from v1 and adds to new patches to improve _git_notes() (sorry I couldn't resist)
Interdiff with what's on 'pu'
contrib/completion/git-completion.bash +6 -8
@@ -1815,7 +1815,7 @@ _git_name_rev () _git_notes () { - local subcommands='add append copy edit list prune remove show' + local subcommands='add append copy edit get-ref list merge prune remove show' local subcommand="$(__git_find_on_cmdline "$subcommands")" case "$subcommand,$cur" in
@@ -1832,18 +1832,15 @@ _git_notes () ;; esac ;; - add,--reuse-message=*|append,--reuse-message=*|\ - add,--reedit-message=*|append,--reedit-message=*) + *,--reuse-message=*|*,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; - prune,--*) - __gitcomp_builtin notes_prune - ;; - prune,*) - ;; *,--*) __gitcomp_builtin notes_$subcommand ;; + prune,*|get-ref,*) + # this command does not take a ref, do not complete it + ;; *) case "$prev" in -m|-F)
@@ -1956,6 +1953,7 @@ _git_rebase () --autostash --no-autostash --verify --no-verify --keep-empty --root --force-rebase --no-ff + --rerere-autoupdate --exec "
Nguyễn Thái Ngọc Duy (4):
completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate
completion: simplify _git_notes
completion: complete --{reuse,reedit}-message= for all notes subcmds
completion: more subcommands in _git_notes()
contrib/completion/git-completion.bash | 25 ++++++++----------------- parse-options.h | 4 ++-- rerere.h | 3 +-- 3 files changed, 11 insertions(+), 21 deletions(-)
Signature · 1 line
2.16.2.785.g429c04a1b9
PATCH v2 1/4 completion: don't set PARSE_OPT_NOCOMPLETE on --rerere-autoupdate
There is not a strong reason to hide this option, and git-merge already completes this one. Let's allow to complete this for all commands (and let git-completion.bash do the suppressing if needed).
This makes --rerere-autoupdate completable for am, cherry-pick and revert. rebase completion is fixed manually because it's a shell script and does not benefit from --git-completion-helper.
--- contrib/completion/git-completion.bash | 4 ++-- parse-options.h | 4 ++-- rerere.h | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-)
contrib/completion/git-completion.bash +2 -2
@@ -1754,8 +1754,7 @@ _git_merge () case "$cur" in --*) - __gitcomp_builtin merge "--rerere-autoupdate - --no-rerere-autoupdate + __gitcomp_builtin merge "--no-rerere-autoupdate --no-commit --no-edit --no-ff --no-log --no-progress --no-squash --no-stat
@@ -1963,6 +1962,7 @@ _git_rebase () --autostash --no-autostash --verify --no-verify --keep-empty --root --force-rebase --no-ff + --rerere-autoupdate --exec "
parse-options.h +2 -2
@@ -148,8 +148,8 @@ struct option {#define OPT_STRING_LIST (s, l, v, a, h) \ { OPTION_CALLBACK, (s), (l), (v), (a), \ (h), 0, &parse_opt_string_list } -#define OPT_UYN (s, l, v, h, f) { OPTION_CALLBACK, (s), (l), (v), NULL, \ - (h), PARSE_OPT_NOARG|(f), &parse_opt_tertiary } +#define OPT_UYN (s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, &parse_opt_tertiary }#define OPT_DATE (s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \ parse_opt_approxidate_cb }
rerere.h +1 -2
@@ -37,7 +37,6 @@ extern void rerere_clear(struct string_list *);extern void rerere_gc (struct string_list *);#define OPT_RERERE_AUTOUPDATE (v) OPT_UYN(0, "rerere-autoupdate", (v), \ - N_("update the index with reused conflict resolution if possible"), \ - PARSE_OPT_NOCOMPLETE) + N_("update the index with reused conflict resolution if possible"))#endif
Signature · 1 line
2.16.2.785.g429c04a1b9
PATCH v2 2/4 completion: simplify _git_notes
In reply to Nguyễn Thái Ngọc DuyThis also adds completion for 'git notes remove' and 'git notes edit'.
--- contrib/completion/git-completion.bash | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
contrib/completion/git-completion.bash +3 -11
@@ -1836,19 +1836,11 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; - add,--*) - __gitcomp_builtin notes_add - ;; - append,--*) - __gitcomp_builtin notes_append - ;; - copy,--*) - __gitcomp_builtin notes_copy - ;; - prune,--*) - __gitcomp_builtin notes_prune + *,--*) + __gitcomp_builtin notes_$subcommand ;; prune,*) + # this command does not take a ref, do not complete it ;; *) case "$prev" in
Signature · 1 line
2.16.2.785.g429c04a1b9
PATCH v2 3/4 completion: complete --{reuse,reedit}-message= for all notes subcmds
In reply to Nguyễn Thái Ngọc DuyThe new subcommand that takes these options is 'git notes edit'. Just accept the options from subcommands since we handle them the same way in builtin/notes.c anyway. If a user does
git prune --reuse-message=...
just let the command catches that error when it's executed.
--- contrib/completion/git-completion.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
contrib/completion/git-completion.bash +1 -2
@@ -1832,8 +1832,7 @@ _git_notes () ;; esac ;; - add,--reuse-message=*|append,--reuse-message=*|\ - add,--reedit-message=*|append,--reedit-message=*) + *,--reuse-message=*|*,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; *,--*)
Signature · 1 line
2.16.2.785.g429c04a1b9
PATCH v2 4/4 completion: more subcommands in _git_notes()
In reply to Nguyễn Thái Ngọc DuyTwo subcommands are added for completion: merge and get-ref. get-ref is more like plumbing. But since it does not share the prefix with any other subcommands, it won't slow anybody down.
--- contrib/completion/git-completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
contrib/completion/git-completion.bash +2 -2
@@ -1815,7 +1815,7 @@ _git_name_rev () _git_notes () { - local subcommands='add append copy edit list prune remove show' + local subcommands='add append copy edit get-ref list merge prune remove show' local subcommand="$(__git_find_on_cmdline "$subcommands")" case "$subcommand,$cur" in
@@ -1838,7 +1838,7 @@ _git_notes () *,--*) __gitcomp_builtin notes_$subcommand ;; - prune,*) + prune,*|get-ref,*) # this command does not take a ref, do not complete it ;; *)
Signature · 1 line
2.16.2.785.g429c04a1b9
Re: [PATCH 2/2] completion: simplify _git_notes
In reply to Junio C HamanoQuoted 57 lines
Quoted 5 lines · SZEDER Gábor
There is a minor behaviour change here, though. This
prune,*)
;;Quoted 14 lines
case arm ensured that we don't list refs for 'git notes prune <TAB>', because it doesn't accept them (and then we take our usual fallback and let Bash complete filenames; yeah, 'git notes prune' doesn't accept filenames either, but, as I said, that's our usual fallback when we can't offer anything for completion).
This patch removes that case arm, and refs will be offered for 'git notes prune <TAB>'.
Quoted 5 lines
(quoted diff) +2
-0+ *,--*) + __gitcomp_builtin notes_$subcommand ;; *) case "$prev" inI have this tentatively queued on the topic. Can we wrap the topic up and move it forward, instead of leaving it (and other topics) hanging around and causing conflicts with other topics in flight, please?
Thanks.
Subject: [PATCH] SQUASH???
By Szeder <CAM0VKjmmF2t=B2s3rJoKmO3j6Bk5d6PEfCV==ONRGMcdUMLFpQ@mail.gmail.com>
--- contrib/completion/git-completion.bash | 5 +++++ 1 file changed, 5 insertions(+)contrib/completion/git-completion.bash +5
-0@@ -1836,6 +1836,11 @@ _git_notes () add,--reedit-message=*|append,--reedit-message=*) __git_complete_refs --cur="${cur#*=}" ;; + prune,--*) + __gitcomp_builtin notes_prune + ;; + prune,*) + ;; *,--*) __gitcomp_builtin notes_$subcommand ;;Signature · 1 line
2.16.2-345-g7e31236f65
That works fine, but this would work just as well and has one less case arm:
contrib/completion/git-completion.bash +2 -0
@@ -1839,6 +1839,8 @@ _git_notes () *,--*) __gitcomp_builtin notes_$subcommand ;; + prune,*) + ;; *) case "$prev" in -m|-F)
Re: [PATCH 2/2] completion: simplify _git_notes
Quoted 2 lines · SZEDER Gábor
That works fine, but this would work just as well and has one less case arm:
OK, I missed that "obvious optimization" opportunity. I agree that would work.
Quoted 14 lines
contrib/completion/git-completion.bash +2
-0@@ -1839,6 +1839,8 @@ _git_notes () *,--*) __gitcomp_builtin notes_$subcommand ;; + prune,*) + ;; *) case "$prev" in -m|-F)