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

Re: [PATCH RFC] diff --no-index: teach option to exclude files by pattern

From
Junio C Hamano <gitster@pobox.com>
Date
May 14, 2025, 21:10 UTC
Message-ID
<xmqqzffe7vbh.fsf@gitster.g>
In-Reply-To
<20250514204014.3106177-1-jacob.e.keller@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 7 quoted lines
> From: Jacob Keller <jacob.keller@gmail.com>
>
> Teach git diff --no-index the ability to exclude files by wildmatch
> pattern when recursing through directories. The '--exclude' option
> builds up a string list containing the patterns. These are checked with
> wildmatch() in the read_directory_contents function. If any pattern
> matches, then the file is not included in the directory contents.
A quite natural question that comes to mind is:
    How would we do this for the normal "git diff" that is not the
    bolted on '--no-index' mode?
but ...
> The --exclude option is only supported by the --no-index mode. Standard
> diff modes support negative pathspecs which is more powerful. I tried to
> see if there was a way to add support for negative pathspecs themselves,
> but haven't yet figured out if this is possible.

... of course you have thought about it already. I do agree with you that we should figure out how and teach this mode to also use pathspec, not necessarily only the negative ones but positive ones.

After all,
    $ git diff --no-index [<option>...] dirA dirB
is like running
    $ diff -r [<option>...] dirA dirB
after preparing these two directories like so:
    $ git archive revA | ( mkdir dirA && tar Cxf dirA - )
    $ git archive revB | ( mkdir dirB && tar Cxf dirB - )

Hence it is natural for users to expect that anything you can do with

    $ git diff revA revB
should be doable, in
    $ git diff --no-index dirA dirB

and vice versa. And as you said, when comparing two revisions, you'd use pathspec for this kind of thing.

    $ git diff revA revB -- Documentation/ t/ ':!po/'

So, I pretty much agree with the need to be able to exclude some parts of the tree(s) from comparison in "diff --no-index" mode, but I doubt it is a good idea to tell what to exclude the "--no-index" mode in a completely different way.

The last time I looked at it, I got an impression that the command line argument parsing of "git diff --no-index" was messy (which is sort of inevitable, since unlike the normal "git diff", it can compare more than just two "collections"---it can take two paths to regular files, for example, and in such a case pathspec arguments can play no role), so teaching it pathspec parsing might be a bit of work, though.

Thanks for starting an interesting topic.
Previous: Jacob KellerNext: Jacob Keller
Message 2 of 5 in “diff --no-index: teach option to exclude files by pattern”
  1. diff --no-index: teach option to exclude files by patternJacob Keller, May 14, 2025
  2. Junio C HamanoMay 14, 2025
  3. Jacob KellerMay 15, 2025
  4. Junio C HamanoMay 15, 2025
  5. Jacob KellerMay 15, 2025

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.