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

[PATCH v4 1/3] pathspec: add match_leading_pathspec variant

From
Jacob Keller <jacob.e.keller@intel.com>
Date
May 21, 2025, 23:29 UTC
Message-ID
<20250521232917.2333291-2-jacob.e.keller@intel.com>
In-Reply-To
<20250521232917.2333291-1-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>

The do_match_pathspec() function has the DO_MATCH_LEADING_PATHSPEC option to allow pathspecs to match when matching "src" against a pathspec like "src/path/...". This support is not exposed by match_pathspec, and the internal flags to do_match_pathspec are not exposed outside of dir.c

The upcoming support for pathspecs in git diff --no-index need the LEADING matching behavior when iterating down through a directory with readdir.

We could try to expose the match_pathspec_with_flags to the public API. However, DO_MATCH_EXCLUDES really shouldn't be public, and its a bit weird to only have a few of the flags become public.

Instead, add match_leading_pathspec() as a function which sets both DO_MATCH_DIRECTORY and DO_MATCH_LEADING_PATHSPEC when is_dir is true.

This will be used in a following change to support pathspec matching in git diff --no-index.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 pathspec.h |  6 ++++++
 dir.c      | 10 ++++++++++
 2 files changed, 16 insertions(+)
diff --git a/pathspec.h b/pathspec.h
index de537cff3cb6..cda3eb5b91f7 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -184,6 +184,12 @@ int match_pathspec(struct index_state *istate,
 		   const char *name, int namelen,
 		   int prefix, char *seen, int is_dir);
 
+/* Set both DO_MATCH_DIRECTORY and DO_MATCH_LEADING_PATHSPEC if is_dir true */
+int match_leading_pathspec(struct index_state *istate,
+			   const struct pathspec *ps,
+			   const char *name, int namelen,
+			   int prefix, char *seen, int is_dir);
+
 /*
  * Determine whether a pathspec will match only entire index entries (non-sparse
  * files and/or entire sparse directories). If the pathspec has the potential to
diff --git a/dir.c b/dir.c
index a374972b6243..86eb77b82a79 100644
--- a/dir.c
+++ b/dir.c
@@ -577,6 +577,16 @@ int match_pathspec(struct index_state *istate,
 					 prefix, seen, flags);
 }
 
+int match_leading_pathspec(struct index_state *istate,
+			   const struct pathspec *ps,
+			   const char *name, int namelen,
+			   int prefix, char *seen, int is_dir)
+{
+	unsigned flags = is_dir ? DO_MATCH_DIRECTORY | DO_MATCH_LEADING_PATHSPEC : 0;
+	return match_pathspec_with_flags(istate, ps, name, namelen,
+					 prefix, seen, flags);
+}
+
 /**
  * Check if a submodule is a superset of the pathspec
  */
-- 
2.48.1.397.gec9d649cc640
Previous: Jacob KellerNext: Jacob Keller
Message 2 of 22 in “diff: add pathspec support to --no-index”
  1. 0/3 diff: add pathspec support to --no-indexJacob Keller, May 21, 2025
  2. 1/3 pathspec: add match_leading_pathspec variantJacob Keller, May 21, 2025
  3. 2/3 pathspec: add flag to indicate operation without repositoryJacob Keller, May 21, 2025
  4. 3/3 diff --no-index: support limiting by pathspecJacob Keller, May 21, 2025
  5. Ben KnobleJun 4, 2025
  6. Jacob KellerJun 4, 2025
  7. Jacob KellerJun 4, 2025
  8. Junio C HamanoJun 4, 2025
  9. Jacob KellerJun 4, 2025
  10. D. Ben KnobleJun 4, 2025
  11. Junio C HamanoJun 4, 2025
  12. Johannes SchindelinSep 23, 2025
  13. Jacob KellerSep 23, 2025
  14. Johannes SchindelinSep 24, 2025
  15. Jacob KellerSep 24, 2025
  16. Jacob KellerSep 24, 2025
  17. Junio C HamanoMay 22, 2025
  18. Jacob KellerMay 22, 2025
  19. Junio C HamanoMay 22, 2025
  20. Junio C HamanoJun 3, 2025
  21. Ben KnobleJun 4, 2025
  22. Phillip WoodJun 5, 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.