Skip to content

Commit 6e4fb00

Browse files
jacob-kellergitster
authored andcommitted
pathspec: add match_leading_pathspec variant
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8613c2b commit 6e4fb00

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

dir.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,16 @@ int match_pathspec(struct index_state *istate,
577577
prefix, seen, flags);
578578
}
579579

580+
int match_leading_pathspec(struct index_state *istate,
581+
const struct pathspec *ps,
582+
const char *name, int namelen,
583+
int prefix, char *seen, int is_dir)
584+
{
585+
unsigned flags = is_dir ? DO_MATCH_DIRECTORY | DO_MATCH_LEADING_PATHSPEC : 0;
586+
return match_pathspec_with_flags(istate, ps, name, namelen,
587+
prefix, seen, flags);
588+
}
589+
580590
/**
581591
* Check if a submodule is a superset of the pathspec
582592
*/

pathspec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ int match_pathspec(struct index_state *istate,
184184
const char *name, int namelen,
185185
int prefix, char *seen, int is_dir);
186186

187+
/* Set both DO_MATCH_DIRECTORY and DO_MATCH_LEADING_PATHSPEC if is_dir true */
188+
int match_leading_pathspec(struct index_state *istate,
189+
const struct pathspec *ps,
190+
const char *name, int namelen,
191+
int prefix, char *seen, int is_dir);
192+
187193
/*
188194
* Determine whether a pathspec will match only entire index entries (non-sparse
189195
* files and/or entire sparse directories). If the pathspec has the potential to

0 commit comments

Comments
 (0)