git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 15/17] completion: add and use --list-cmds=nohelpers

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
May 20, 2018, 18:40 UTC
Message-ID
<20180520184009.976-16-pclouds@gmail.com>
In-Reply-To
<20180520184009.976-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git.txt                  |  3 ++-
 contrib/completion/git-completion.bash | 20 ++++----------------
 git.c                                  | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index c423810eac..820ab77fcb 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -169,7 +169,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
 	groups are: builtins, parseopt (builtin commands that use
 	parse-options), main (all commands in libexec directory),
 	others (all other commands in `$PATH` that have git- prefix),
-	list-<category> (see categories in command-list.txt)
+	list-<category> (see categories in command-list.txt),
+	nohelpers (exclude helper commands).
 
 GIT COMMANDS
 ------------
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index cd1d8e553f..217c8a3d3b 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -843,7 +843,7 @@ __git_commands () {
 		then
 			printf "%s" "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
 		else
-			git --list-cmds=list-mainporcelain,others,list-complete
+			git --list-cmds=list-mainporcelain,others,nohelpers,list-complete
 		fi
 		;;
 	all)
@@ -851,27 +851,15 @@ __git_commands () {
 		then
 			printf "%s" "$GIT_TESTING_ALL_COMMAND_LIST"
 		else
-			git --list-cmds=main,others
+			git --list-cmds=main,others,nohelpers
 		fi
 		;;
 	esac
 }
 
-__git_list_commands ()
-{
-	local i IFS=" "$'\n'
-	for i in $(__git_commands $1)
-	do
-		case $i in
-		*--*)             : helper pattern;;
-		*) echo $i;;
-		esac
-	done
-}
-
 __git_list_all_commands ()
 {
-	__git_list_commands all
+	__git_commands all
 }
 
 __git_all_commands=
@@ -883,7 +871,7 @@ __git_compute_all_commands ()
 
 __git_list_porcelain_commands ()
 {
-	__git_list_commands porcelain
+	__git_commands porcelain
 }
 
 __git_porcelain_commands=
diff --git a/git.c b/git.c
index 19f73b3fa3..f6ae79ffaf 100644
--- a/git.c
+++ b/git.c
@@ -39,6 +39,18 @@ static int use_pager = -1;
 
 static void list_builtins(struct string_list *list, unsigned int exclude_option);
 
+static void exclude_helpers_from_list(struct string_list *list)
+{
+	int i = 0;
+
+	while (i < list->nr) {
+		if (strstr(list->items[i].string, "--"))
+			unsorted_string_list_delete_item(list, i, 0);
+		else
+			i++;
+	}
+}
+
 static int match_token(const char *spec, int len, const char *token)
 {
 	int token_len = strlen(token);
@@ -61,6 +73,8 @@ static int list_cmds(const char *spec)
 			list_all_main_cmds(&list);
 		else if (match_token(spec, len, "others"))
 			list_all_other_cmds(&list);
+		else if (match_token(spec, len, "nohelpers"))
+			exclude_helpers_from_list(&list);
 		else if (len > 5 && !strncmp(spec, "list-", 5)) {
 			struct strbuf sb = STRBUF_INIT;
 
-- 
2.17.0.705.g3525833791
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 31 of 40 in “nd/command-list updates”
  1. 00/14 nd/command-list updatesNguyễn Thái Ngọc Duy, May 19, 2018
  2. 01/14 generate-cmds.sh: factor out synopsis extract codeNguyễn Thái Ngọc Duy, May 19, 2018
  3. 02/14 generate-cmds.sh: export all commands to command-list.hNguyễn Thái Ngọc Duy, May 19, 2018
  4. 06/14 git --list-cmds: collect command list in a string_listNguyễn Thái Ngọc Duy, May 19, 2018
  5. 07/14 completion: implement and use --list-cmds=main,othersNguyễn Thái Ngọc Duy, May 19, 2018
  6. 09/14 help: add "-a --verbose" to list all commands with synopsisNguyễn Thái Ngọc Duy, May 19, 2018
  7. 08/14 git: support --list-cmds=list-<category>Nguyễn Thái Ngọc Duy, May 19, 2018
  8. 05/14 git.c: convert --list-* to --list-cmds=*Nguyễn Thái Ngọc Duy, May 19, 2018
  9. 04/14 Remove common-cmds.hNguyễn Thái Ngọc Duy, May 19, 2018
  10. 14/14 completion: allow to customize the completable command listNguyễn Thái Ngọc Duy, May 19, 2018
  11. SZEDER GáborMay 20, 2018
  12. Duy NguyenMay 20, 2018
  13. 13/14 completion: reduce completable command listNguyễn Thái Ngọc Duy, May 19, 2018
  14. SZEDER GáborMay 20, 2018
  15. Junio C HamanoMay 21, 2018
  16. 10/14 help: use command-list.txt for the source of guidesNguyễn Thái Ngọc Duy, May 19, 2018
  17. 03/14 help: use command-list.h for common command listNguyễn Thái Ngọc Duy, May 19, 2018
  18. 11/14 command-list.txt: documentation and guide lineNguyễn Thái Ngọc Duy, May 19, 2018
  19. 12/14 completion: let git provide the completable command listNguyễn Thái Ngọc Duy, May 19, 2018
  20. SZEDER GáborMay 20, 2018
  21. Duy NguyenMay 20, 2018
  22. 00/17 nd/command-list updatesNguyễn Thái Ngọc Duy, May 20, 2018
  23. 01/17 generate-cmds.sh: factor out synopsis extract codeNguyễn Thái Ngọc Duy, May 20, 2018
  24. 02/17 generate-cmds.sh: export all commands to command-list.hNguyễn Thái Ngọc Duy, May 20, 2018
  25. 03/17 help: use command-list.h for common command listNguyễn Thái Ngọc Duy, May 20, 2018
  26. 07/17 completion: implement and use --list-cmds=main,othersNguyễn Thái Ngọc Duy, May 20, 2018
  27. 06/17 git --list-cmds: collect command list in a string_listNguyễn Thái Ngọc Duy, May 20, 2018
  28. 08/17 git: support --list-cmds=list-<category>Nguyễn Thái Ngọc Duy, May 20, 2018
  29. 13/17 completion: reduce completable command listNguyễn Thái Ngọc Duy, May 20, 2018
  30. 14/17 Move declaration for alias.c to alias.hNguyễn Thái Ngọc Duy, May 20, 2018
  31. 15/17 completion: add and use --list-cmds=nohelpersNguyễn Thái Ngọc Duy, May 20, 2018
  32. 12/17 completion: let git provide the completable command listNguyễn Thái Ngọc Duy, May 20, 2018
  33. 11/17 command-list.txt: documentation and guide lineNguyễn Thái Ngọc Duy, May 20, 2018
  34. 10/17 help: use command-list.txt for the source of guidesNguyễn Thái Ngọc Duy, May 20, 2018
  35. Ævar Arnfjörð BjarmasonNov 20, 2018
  36. 17/17 completion: allow to customize the completable command listNguyễn Thái Ngọc Duy, May 20, 2018
  37. 16/17 completion: add and use --list-cmds=aliasNguyễn Thái Ngọc Duy, May 20, 2018
  38. 05/17 git.c: convert --list-* to --list-cmds=*Nguyễn Thái Ngọc Duy, May 20, 2018
  39. 04/17 Remove common-cmds.hNguyễn Thái Ngọc Duy, May 20, 2018
  40. 09/17 help: add "-a --verbose" to list all commands with synopsisNguyễn Thái Ngọc Duy, May 20, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.