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

[PATCH v3 2/4] pathspec: expose match_pathspec_with_flags

From
Jacob Keller <jacob.e.keller@intel.com>
Date
May 20, 2025, 00:01 UTC
Message-ID
<20250520000125.2162144-3-jacob.e.keller@intel.com>
In-Reply-To
<20250520000125.2162144-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

Make match_pathspec_with_flags public, and expose the DO_MATCH_LEADING_PATHSPEC and DO_MATCH_DIRECTORY flags. The DO_MATCH_EXCLUDE flag is kept private in dir.c

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

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
 pathspec.h |  8 ++++++++
 dir.c      | 11 +++++------
 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/pathspec.h b/pathspec.h
index de537cff3cb6..d22d4e80248d 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -184,6 +184,14 @@ int match_pathspec(struct index_state *istate,
 		   const char *name, int namelen,
 		   int prefix, char *seen, int is_dir);
 
+#define DO_MATCH_DIRECTORY (1<<1)
+#define DO_MATCH_LEADING_PATHSPEC (1<<2)
+
+int match_pathspec_with_flags(struct index_state *istate,
+			      const struct pathspec *ps,
+			      const char *name, int namelen,
+			      int prefix, char *seen, unsigned flags);
+
 /*
  * 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..2f2b654b0252 100644
--- a/dir.c
+++ b/dir.c
@@ -329,9 +329,8 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
 	return 1;
 }
 
+// DO_MATCH_EXCLUDE is not public
 #define DO_MATCH_EXCLUDE   (1<<0)
-#define DO_MATCH_DIRECTORY (1<<1)
-#define DO_MATCH_LEADING_PATHSPEC (1<<2)
 
 /*
  * Does the given pathspec match the given name?  A match is found if
@@ -551,10 +550,10 @@ static int do_match_pathspec(struct index_state *istate,
 	return retval;
 }
 
-static int match_pathspec_with_flags(struct index_state *istate,
-				     const struct pathspec *ps,
-				     const char *name, int namelen,
-				     int prefix, char *seen, unsigned flags)
+int match_pathspec_with_flags(struct index_state *istate,
+			      const struct pathspec *ps,
+			      const char *name, int namelen,
+			      int prefix, char *seen, unsigned flags)
 {
 	int positive, negative;
 	positive = do_match_pathspec(istate, ps, name, namelen,
-- 
2.48.1.397.gec9d649cc640
Previous: Jacob KellerNext: Junio C Hamano
Message 5 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.