git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: <git@vger.kernel.org>,  Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH RFC] diff --no-index: teach option to exclude files by pattern
Date: Wed, 14 May 2025 14:10:10 -0700	[thread overview]
Message-ID: <xmqqzffe7vbh.fsf@gitster.g> (raw)
In-Reply-To: <20250514204014.3106177-1-jacob.e.keller@intel.com> (Jacob Keller's message of "Wed, 14 May 2025 13:40:14 -0700")

Jacob Keller <jacob.e.keller@intel.com> writes:

> 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.

  reply	other threads:[~2025-05-14 21:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 20:40 [PATCH RFC] diff --no-index: teach option to exclude files by pattern Jacob Keller
2025-05-14 21:10 ` Junio C Hamano [this message]
2025-05-15 16:27   ` Jacob Keller
2025-05-15 18:09     ` Junio C Hamano
2025-05-15 20:24       ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzffe7vbh.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=jacob.keller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).