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

Re: [BUG] completion.commands does not remove multiple commands

From
Jeff King <peff@peff.net>
Date
Mar 1, 2019, 18:30 UTC
Message-ID
<20190301183017.GB30847@sigill.intra.peff.net>
In-Reply-To
<20190301173443.16429-1-tmz@pobox.com>
On Fri, Mar 01, 2019 at 12:34:40PM -0500, Todd Zullinger wrote:
Show 12 quoted lines
> Jeff King wrote:
> > I can reproduce your problem, though the test you included passes for me
> > even with the current tip of master.
> 
> Oh, hrm.  I think the issue is that completion.commands needs to be
> set in the global (or system-wide) config, via test_config_global
> rather than the local repo config which test_config sets.
> 
> In hindsight, that seems obvious.  But it's probably worth noting
> that where completion.commands is documented, for anyone who might
> spend a few cycles trying to configure it on a per-repo basis before
> realizing it doesn't work.

I think this is actually a bug. Normally code that is checking config before we've decide to do setup_git_directory() would use read_early_config(), which uses discover_git_directory() to tentatively see if we're in a repo, and if so to add it to the config sequence.

But this code uses the caching configset mechanism. And that code (rightly) does not use read_early_config(), because it has no idea if it's being called early or what.

I think we probably ought to be doing something like this:
diff --git a/git.c b/git.c
index 2dd588674f..ba3690245e 100644
--- a/git.c
+++ b/git.c
@@ -62,6 +62,13 @@ static int list_cmds(const char *spec)
 {
 	struct string_list list = STRING_LIST_INIT_DUP;
 	int i;
+	int nongit;
+
+	/*
+	 * Set up the repository so we can pick up any repo-level config (like
+	 * completion.commands).
+	 */
+	setup_git_directory_gently(&nongit);
 
 	while (*spec) {
 		const char *sep = strchrnul(spec, ',');

> I'll leave it to those who know better to follow up with a change to
> use string_list_split().

It's less of an improvement than I'd hoped, since most of the code is
actually handling the "-" thing. So I don't think it's really worth the
churn. But here's what it looks like for reference:

---
 help.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/help.c b/help.c
index 026f881715..9e4d258cb8 100644
--- a/help.c
+++ b/help.c
@@ -373,7 +373,9 @@ void list_cmds_by_category(struct string_list *list,
 
 void list_cmds_by_config(struct string_list *list)
 {
-	const char *cmd_list;
+	const char *cmd_str;
+	struct string_list cmd_list = STRING_LIST_INIT_DUP;
+	int i;
 
 	/*
 	 * There's no actual repository setup at this point (and even
@@ -382,26 +384,22 @@ void list_cmds_by_config(struct string_list *list)
 	 * too since the caller (git --list-cmds=) should exit shortly
 	 * anyway.
 	 */
-	if (git_config_get_string_const("completion.commands", &cmd_list))
+	if (git_config_get_string_const("completion.commands", &cmd_str))
 		return;
 
 	string_list_sort(list);
 	string_list_remove_duplicates(list, 0);
 
-	while (*cmd_list) {
-		struct strbuf sb = STRBUF_INIT;
-		const char *p = strchrnul(cmd_list, ' ');
+	string_list_split(&cmd_list, cmd_str, ' ', -1);
+	for (i = 0; i < cmd_list.nr; i++) {
+		const char *cmd = cmd_list.items[0].string;
 
-		strbuf_add(&sb, cmd_list, p - cmd_list);
-		if (sb.buf[0] == '-')
-			string_list_remove(list, sb.buf + 1, 0);
+		if (*cmd == '-')
+			string_list_remove(list, cmd + 1, 0);
 		else
-			string_list_insert(list, sb.buf);
-		strbuf_release(&sb);
-		while (*p == ' ')
-			p++;
-		cmd_list = p;
+			string_list_insert(list, cmd);
 	}
+	string_list_clear(&cmd_list, 0);
 }
 
 void list_common_guides_help(void)
Previous: Todd ZullingerNext: Todd Zullinger
Message 4 of 35 in “[BUG] completion.commands does not remove multiple commands”
  1. Todd ZullingerFeb 28, 2019
  2. Jeff KingFeb 28, 2019
  3. Todd ZullingerMar 1, 2019
  4. Jeff KingMar 1, 2019
  5. Todd ZullingerMar 1, 2019
  6. Jeff KingMar 1, 2019
  7. Duy NguyenMar 2, 2019
  8. Junio C HamanoMar 2, 2019
  9. Todd ZullingerMar 2, 2019
  10. SZEDER GáborMar 2, 2019
  11. Todd ZullingerMar 3, 2019
  12. Jeff KingMar 3, 2019
  13. 1/3 doc: note config file restrictions for completion.commandsTodd Zullinger, Mar 1, 2019
  14. Duy NguyenMar 17, 2019
  15. 1/4 git: read local config in --list-cmdsTodd Zullinger, Mar 17, 2019
  16. Duy NguyenMar 18, 2019
  17. 0/4 completion.commands: fix multiple command removalsTodd Zullinger, Mar 20, 2019
  18. Junio C HamanoMar 21, 2019
  19. Todd ZullingerMar 21, 2019
  20. Duy NguyenMar 21, 2019
  21. 1/4 git: read local config in --list-cmdsTodd Zullinger, Mar 20, 2019
  22. 2/4 t9902: test multiple removals via completion.commandsTodd Zullinger, Mar 20, 2019
  23. 3/4 completion: fix multiple command removalsTodd Zullinger, Mar 20, 2019
  24. 4/4 completion: use __git when calling --list-cmdsTodd Zullinger, Mar 20, 2019
  25. 0/4 completion.commands: fix multiple command removalsTodd Zullinger, Mar 17, 2019
  26. 2/4 t9902: test multiple removals via completion.commandsTodd Zullinger, Mar 17, 2019
  27. 3/4 completion: fix multiple command removalsTodd Zullinger, Mar 17, 2019
  28. 4/4 completion: use __git when calling --list-cmdsTodd Zullinger, Mar 17, 2019
  29. 2/3 t9902: test multiple removals via completion.commandsTodd Zullinger, Mar 1, 2019
  30. Eric SunshineMar 1, 2019
  31. SZEDER GáborMar 1, 2019
  32. Todd ZullingerMar 1, 2019
  33. 3/3 completion: fix multiple command removalsTodd Zullinger, Mar 1, 2019
  34. Jeff KingMar 1, 2019
  35. SZEDER GáborFeb 28, 2019

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.