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

Re: [bug] git-ls-files sometimes does not list files with pathspec magic ":(exclude)"

From
Jeff King <peff@peff.net>
Date
Jan 14, 2021, 20:21 UTC
Message-ID
<YACnuuQ9ezo6Bb9H@coredump.intra.peff.net>
In-Reply-To
<xmqqa6tc1dab.fsf@gitster.c.googlers.com>
On Wed, Jan 13, 2021 at 06:07:56PM -0800, Junio C Hamano wrote:
> The rule IIUC is that a path must match one of the positive pathspec
> and none of the negative pathspec, but it looks as if there is some
> bogus optimization based on string length.

I dug a little on this earlier this morning, but didn't get far enough to have any confidence that I wasn't barking totally up the wrong tree. But I found the way the "prefix" is passed match_pathspec to be confusing. This seems to make the problem go away:

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae899b8..93796404bd 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -232,7 +232,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
 	    is_submodule_active(repo, ce->name)) {
 		show_submodule(repo, dir, ce->name);
 	} else if (match_pathspec(repo->index, &pathspec, fullname, strlen(fullname),
-				  max_prefix_len, ps_matched,
+				  0, ps_matched,
 				  S_ISDIR(ce->ce_mode) ||
 				  S_ISGITLINK(ce->ce_mode))) {
 		tag = get_tag(ce, tag);

which I guess is likewise disabling the same optimization you're talking
about. But that probably means the bug is in match_pathspec().

(I probably won't look further at this for a while, so please continue
your prodding; I just wanted to drop what little knowledge I came up
with).

-Peff
Previous: Junio C Hamano
Message 3 of 3 in “[bug] git-ls-files sometimes does not list files with pathspec magic ":(exclude)"”
  1. Thomas HallerJan 13, 2021
  2. Junio C HamanoJan 14, 2021
  3. Jeff KingJan 14, 2021

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.