From 719630eb4826ff7f36bc060533dbccc3c96d151c Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Thu, 8 Apr 2021 17:41:25 -0300 Subject: pathspec: allow to ignore SKIP_WORKTREE entries on index matching Add a new enum parameter to `add_pathspec_matches_against_index()` and `find_pathspecs_matching_against_index()`, allowing callers to specify whether these function should attempt to match SKIP_WORKTREE entries or not. This will be used in a future patch to make `git add` display a warning when it is asked to update SKIP_WORKTREE entries. Signed-off-by: Matheus Tavares Signed-off-by: Junio C Hamano --- pathspec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'pathspec.c') diff --git a/pathspec.c b/pathspec.c index 7a229d8d22..6d502e64e5 100644 --- a/pathspec.c +++ b/pathspec.c @@ -21,7 +21,8 @@ */ void add_pathspec_matches_against_index(const struct pathspec *pathspec, const struct index_state *istate, - char *seen) + char *seen, + enum ps_skip_worktree_action sw_action) { int num_unmatched = 0, i; @@ -38,6 +39,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, return; for (i = 0; i < istate->cache_nr; i++) { const struct cache_entry *ce = istate->cache[i]; + if (sw_action == PS_IGNORE_SKIP_WORKTREE && ce_skip_worktree(ce)) + continue; ce_path_match(istate, ce, pathspec, seen); } } @@ -51,10 +54,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, * given pathspecs achieves against all items in the index. */ char *find_pathspecs_matching_against_index(const struct pathspec *pathspec, - const struct index_state *istate) + const struct index_state *istate, + enum ps_skip_worktree_action sw_action) { char *seen = xcalloc(pathspec->nr, 1); - add_pathspec_matches_against_index(pathspec, istate, seen); + add_pathspec_matches_against_index(pathspec, istate, seen, sw_action); return seen; } -- cgit v1.2.3