]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pathspec: add match_leading_pathspec variant
authorJacob Keller <jacob.keller@gmail.com>
Wed, 21 May 2025 23:29:15 +0000 (16:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 May 2025 21:20:11 +0000 (14:20 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
pathspec.h

diff --git a/dir.c b/dir.c
index a374972b6243b62da4db8e7d974d55549cdd98a7..86eb77b82a79597c12199fbf9c585875cbec64c2 100644 (file)
--- 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
  */
index de537cff3cb6953b338dcf94a900da9d736321f2..cda3eb5b91f70f2f8c5138a8f2212fbe7d4b6323 100644 (file)
@@ -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