completion: add and use --list-cmds=nohelpers

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 20, 2018 at 20:40 UTC e11dca10cfb3ef1e561c3e789b346a9719f0344a
3 files changed +20 -17
Documentation/git.txt
+2 -1
@@ -169,7 +169,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
169 groups are: builtins, parseopt (builtin commands that use
170 parse-options), main (all commands in libexec directory),
171 others (all other commands in `$PATH` that have git- prefix),
172 - list-<category> (see categories in command-list.txt)
172 + list-<category> (see categories in command-list.txt),
173 + nohelpers (exclude helper commands).
174
175 GIT COMMANDS
176 ------------
contrib/completion/git-completion.bash
+4 -16
@@ -843,7 +843,7 @@ __git_commands () {
843 then
844 printf "%s" "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
845 else
846 - git --list-cmds=list-mainporcelain,others,list-complete
846 + git --list-cmds=list-mainporcelain,others,nohelpers,list-complete
847 fi
848 ;;
849 all)
@@ -851,27 +851,15 @@ __git_commands () {
851 then
852 printf "%s" "$GIT_TESTING_ALL_COMMAND_LIST"
853 else
854 - git --list-cmds=main,others
854 + git --list-cmds=main,others,nohelpers
855 fi
856 ;;
857 esac
858 }
859
860 -__git_list_commands ()
861 -{
862 - local i IFS=" "$'\n'
863 - for i in $(__git_commands $1)
864 - do
865 - case $i in
866 - *--*) : helper pattern;;
867 - *) echo $i;;
868 - esac
869 - done
870 -}
871 -
860 __git_list_all_commands ()
861 {
874 - __git_list_commands all
862 + __git_commands all
863 }
864
865 __git_all_commands=
@@ -883,7 +871,7 @@ __git_compute_all_commands ()
871
872 __git_list_porcelain_commands ()
873 {
886 - __git_list_commands porcelain
874 + __git_commands porcelain
875 }
876
877 __git_porcelain_commands=
git.c
+14
@@ -39,6 +39,18 @@ static int use_pager = -1;
39
40 static void list_builtins(struct string_list *list, unsigned int exclude_option);
41
42 +static void exclude_helpers_from_list(struct string_list *list)
43 +{
44 + int i = 0;
45 +
46 + while (i < list->nr) {
47 + if (strstr(list->items[i].string, "--"))
48 + unsorted_string_list_delete_item(list, i, 0);
49 + else
50 + i++;
51 + }
52 +}
53 +
54 static int match_token(const char *spec, int len, const char *token)
55 {
56 int token_len = strlen(token);
@@ -61,6 +73,8 @@ static int list_cmds(const char *spec)
73 list_all_main_cmds(&list);
74 else if (match_token(spec, len, "others"))
75 list_all_other_cmds(&list);
76 + else if (match_token(spec, len, "nohelpers"))
77 + exclude_helpers_from_list(&list);
78 else if (len > 5 && !strncmp(spec, "list-", 5)) {
79 struct strbuf sb = STRBUF_INIT;
80