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

[PATCH v3 0/4] diff: add pathspec support to --no-index

From
Jacob Keller <jacob.e.keller@intel.com>
Date
May 20, 2025, 00:01 UTC
Message-ID
<20250520000125.2162144-1-jacob.e.keller@intel.com>
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
Next: Jacob Keller
Message 1 of 15 in “diff: add pathspec support to --no-index”
  1. 0/4 diff: add pathspec support to --no-indexJacob Keller, May 20, 2025
  2. 1/4 prefix_path: support prefixes not ending in trailing slashJacob Keller, May 20, 2025
  3. Junio C HamanoMay 20, 2025
  4. Jacob KellerMay 20, 2025
  5. 2/4 pathspec: expose match_pathspec_with_flagsJacob Keller, May 20, 2025
  6. Junio C HamanoMay 20, 2025
  7. Jacob KellerMay 20, 2025
  8. 3/4 pathspec: add flag to indicate operation without repositoryJacob Keller, May 20, 2025
  9. Junio C HamanoMay 20, 2025
  10. Jacob KellerMay 20, 2025
  11. Jacob KellerMay 21, 2025
  12. 4/4 diff --no-index: support limiting by pathspecJacob Keller, May 20, 2025
  13. Junio C HamanoMay 20, 2025
  14. Jacob KellerMay 20, 2025
  15. Jacob KellerMay 20, 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.