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 <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matheus Tavares committed
Apr 8, 2021 at 17:41 UTC
719630eb4826ff7f36bc060533dbccc3c96d151c
4 files changed
+21
-8
builtin/add.c
+4
-2
@@ -177,7 +177,8 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
177
*dst++ = entry;
178
}
179
dir->nr = dst - dir->entries;
180
- add_pathspec_matches_against_index(pathspec, &the_index, seen);
180
+ add_pathspec_matches_against_index(pathspec, &the_index, seen,
181
+ PS_HEED_SKIP_WORKTREE);
182
return seen;
183
}
184
@@ -578,7 +579,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
579
int i;
580
581
if (!seen)
581
- seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
582
+ seen = find_pathspecs_matching_against_index(&pathspec,
583
+ &the_index, PS_HEED_SKIP_WORKTREE);
584
585
/*
586
* file_exists() assumes exact match
builtin/check-ignore.c
+2
-1
@@ -100,7 +100,8 @@ static int check_ignore(struct dir_struct *dir,
100
* should not be ignored, in order to be consistent with
101
* 'git status', 'git add' etc.
102
*/
103
- seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
103
+ seen = find_pathspecs_matching_against_index(&pathspec, &the_index,
104
+ PS_HEED_SKIP_WORKTREE);
105
for (i = 0; i < pathspec.nr; i++) {
106
full_path = pathspec.items[i].match;
107
pattern = NULL;
pathspec.c
+7
-3
@@ -21,7 +21,8 @@
21
*/
22
void add_pathspec_matches_against_index(const struct pathspec *pathspec,
23
const struct index_state *istate,
24
- char *seen)
24
+ char *seen,
25
+ enum ps_skip_worktree_action sw_action)
26
{
27
int num_unmatched = 0, i;
28
@@ -38,6 +39,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
39
return;
40
for (i = 0; i < istate->cache_nr; i++) {
41
const struct cache_entry *ce = istate->cache[i];
42
+ if (sw_action == PS_IGNORE_SKIP_WORKTREE && ce_skip_worktree(ce))
43
+ continue;
44
ce_path_match(istate, ce, pathspec, seen);
45
}
46
}
@@ -51,10 +54,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
54
* given pathspecs achieves against all items in the index.
55
*/
56
char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
54
- const struct index_state *istate)
57
+ const struct index_state *istate,
58
+ enum ps_skip_worktree_action sw_action)
59
{
60
char *seen = xcalloc(pathspec->nr, 1);
57
- add_pathspec_matches_against_index(pathspec, istate, seen);
61
+ add_pathspec_matches_against_index(pathspec, istate, seen, sw_action);
62
return seen;
63
}
64
pathspec.h
+8
-2
@@ -149,11 +149,17 @@ static inline int ps_strcmp(const struct pathspec_item *item,
149
return strcmp(s1, s2);
150
}
151
152
+enum ps_skip_worktree_action {
153
+ PS_HEED_SKIP_WORKTREE = 0,
154
+ PS_IGNORE_SKIP_WORKTREE = 1
155
+};
156
void add_pathspec_matches_against_index(const struct pathspec *pathspec,
157
const struct index_state *istate,
154
- char *seen);
158
+ char *seen,
159
+ enum ps_skip_worktree_action sw_action);
160
char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
156
- const struct index_state *istate);
161
+ const struct index_state *istate,
162
+ enum ps_skip_worktree_action sw_action);
163
int match_pathspec_attrs(const struct index_state *istate,
164
const char *name, int namelen,
165
const struct pathspec_item *item);