Re: [bug] git-ls-files sometimes does not list files with pathspec magic ":(exclude)"
To
Thomas Haller
Cc
git@vger.kernel.org
From
Junio C Hamano
See Also
Prev
Date
2021-01-14 02:07:56 UTC
Thomas Haller <thaller@redhat.com> writes:

>       git ls-files -- src/platform/ ":(exclude)shared/n-acd"

This does look interesting.

$ git ls-files -- src/platform/ ":(exclude)shared/n-acd"
$ git ls-files -- src/platform/ ":(exclude)??????/?????"
$ git ls-files -- src/platform/ ":(exclude)??????/????"
$ git ls-files -- src/platform/ ":(exclude)??????/???"
$ git ls-files -- src/platform/ ":(exclude)??????/??"
$ git ls-files -- src/platform/ ":(exclude)??????/?"

None of the above gives any output.  And the '/' seems to be a red
herring.  None of the below (where the '/' in the exclude pathspec
is replaced with a single '?') gives any output, either.

$ git ls-files -- src/platform/ ":(exclude)????????????"
$ git ls-files -- src/platform/ ":(exclude)???????????"
$ git ls-files -- src/platform/ ":(exclude)??????????"
$ git ls-files -- src/platform/ ":(exclude)?????????"
$ git ls-files -- src/platform/ ":(exclude)????????"

But if we add one more "?" to the longuest ones, i.e.

$ git ls-files -- src/platform/ ":(exclude)?????????????"
$ git ls-files -- src/platform/ ":(exclude)shared/n-acd?"

we start seeing output.

What is curious is that the longest problematic negative pathspec,
"shared/n-acd" or "????????????", have the same length as
"src/platform" without the trailing slash.

    "shared/n-acd"
    "src/platform/"
    "????????????"

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.

An experiment.  These ought to do the same as the first exacmple:

$ git ls-files -- src/platform/ ":(exclude)shared/n-ac[d]"
$ git ls-files -- src/platform/ ":(exclude)shared/n-[acd][acd][acd]"

but probably because of the character class [d], it seems to
defeat/bypass the broken "optimization" and gives what we expect
back.

I'll have to go back to the desk where I have a development
environment (not an end user enviornment) to dig deeper, but this is
intriguing.  I'll look more later unless somebody else beats me to
it.

Thanks for a report.