git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Jacob Keller <jacob.keller@gmail.com>
Subject: [PATCH v3 0/4] diff: add pathspec support to --no-index
Date: Mon, 19 May 2025 17:01:21 -0700	[thread overview]
Message-ID: <20250520000125.2162144-1-jacob.e.keller@intel.com> (raw)

From: Jacob Keller <jacob.keller@gmail.com>

This series adds support for using pathspecs to limit the comparison when
using git diff --no-index. This is similar to how you can limit what is
included with pathspecs when comparing inside a repository.

This likely still needs some reworks, and I have some open questions in the
final implementation:

 1) pathspecs must all come after the first two path arguments, you
    can't re-arrange them to come first. I'm treating them sort of like
    the treeish arguments to git diff-tree.

 2) The pathspecs are interpreted relative to the provided paths, and
    thus will always need to be specified as relative paths, and will be
    interpreted as relative to the root of the search for each path
    separately.

 3) negative pathspecs have to be fully qualified from the root, i.e.
    ':(exclude)file' will only exclude 'a/file' and not 'a/b/file'
    unless you also use '(glob)' or similar. I think this matches the
    other pathspec support, but I an not 100% sure.

  4) I'm not certain about exposing match_pathspec_with_flags as-is,
     since DO_MATCH_EXCLUDE shouldn't be passed. I got the behavior I
     expected with DO_MATCH_LEADING_PATHSPEC, but it feels a bit of a
     weird API. Perhaps match_pathspec could set both flags when is_dir
     is true? But would that break other callers?

However, this version now has documentation and some test cases. I found a
few issues with my original implementation in v2, which I've fixed.

I also an open to suggestions on better ways to handle the matching.
Currently I need a separate set of pathspecs for both paths, since I need to
make sure they get rooted appropriately. I don't know if there is a better
solution that would allow using the same pathspec structure for both
comparisons.

Jacob Keller (4):
  prefix_path: support prefixes not ending in trailing slash
  pathspec: expose match_pathspec_with_flags
  pathspec: add flag to indicate operation without repository
  diff --no-index: support limiting by pathspec

 pathspec.h                  |  13 +++++
 builtin/diff.c              |   2 +-
 diff-no-index.c             |  91 ++++++++++++++++++++++++------
 dir.c                       |  20 ++++---
 pathspec.c                  |   6 +-
 setup.c                     |   4 +-
 Documentation/git-diff.adoc |  10 +++-
 t/t0060-path-utils.sh       |  18 ++++++
 t/t4053-diff-no-index.sh    | 107 ++++++++++++++++++++++++++++++++++++
 9 files changed, 240 insertions(+), 31 deletions(-)

-- 
2.48.1.397.gec9d649cc640


             reply	other threads:[~2025-05-20  0:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-20  0:01 Jacob Keller [this message]
2025-05-20  0:01 ` [PATCH v3 1/4] prefix_path: support prefixes not ending in trailing slash Jacob Keller
2025-05-20 14:35   ` Junio C Hamano
2025-05-20 22:34     ` Jacob Keller
2025-05-20  0:01 ` [PATCH v3 2/4] pathspec: expose match_pathspec_with_flags Jacob Keller
2025-05-20 14:39   ` Junio C Hamano
2025-05-20 22:38     ` Jacob Keller
2025-05-20  0:01 ` [PATCH v3 3/4] pathspec: add flag to indicate operation without repository Jacob Keller
2025-05-20 15:13   ` Junio C Hamano
2025-05-20 22:42     ` Jacob Keller
2025-05-21 23:05     ` Jacob Keller
2025-05-20  0:01 ` [PATCH v3 4/4] diff --no-index: support limiting by pathspec Jacob Keller
2025-05-20 16:30   ` Junio C Hamano
2025-05-20 22:45     ` Jacob Keller
2025-05-20 22:47     ` 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=20250520000125.2162144-1-jacob.e.keller@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).