Skip to content

Commit 719630e

Browse files
matheustavaresgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d73dbaf commit 719630e

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

builtin/add.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
177177
*dst++ = entry;
178178
}
179179
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);
181182
return seen;
182183
}
183184

@@ -578,7 +579,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
578579
int i;
579580

580581
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);
582584

583585
/*
584586
* file_exists() assumes exact match

builtin/check-ignore.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ static int check_ignore(struct dir_struct *dir,
100100
* should not be ignored, in order to be consistent with
101101
* 'git status', 'git add' etc.
102102
*/
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);
104105
for (i = 0; i < pathspec.nr; i++) {
105106
full_path = pathspec.items[i].match;
106107
pattern = NULL;

pathspec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
*/
2222
void add_pathspec_matches_against_index(const struct pathspec *pathspec,
2323
const struct index_state *istate,
24-
char *seen)
24+
char *seen,
25+
enum ps_skip_worktree_action sw_action)
2526
{
2627
int num_unmatched = 0, i;
2728

@@ -38,6 +39,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
3839
return;
3940
for (i = 0; i < istate->cache_nr; i++) {
4041
const struct cache_entry *ce = istate->cache[i];
42+
if (sw_action == PS_IGNORE_SKIP_WORKTREE && ce_skip_worktree(ce))
43+
continue;
4144
ce_path_match(istate, ce, pathspec, seen);
4245
}
4346
}
@@ -51,10 +54,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
5154
* given pathspecs achieves against all items in the index.
5255
*/
5356
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)
5559
{
5660
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);
5862
return seen;
5963
}
6064

pathspec.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@ static inline int ps_strcmp(const struct pathspec_item *item,
149149
return strcmp(s1, s2);
150150
}
151151

152+
enum ps_skip_worktree_action {
153+
PS_HEED_SKIP_WORKTREE = 0,
154+
PS_IGNORE_SKIP_WORKTREE = 1
155+
};
152156
void add_pathspec_matches_against_index(const struct pathspec *pathspec,
153157
const struct index_state *istate,
154-
char *seen);
158+
char *seen,
159+
enum ps_skip_worktree_action sw_action);
155160
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);
157163
int match_pathspec_attrs(const struct index_state *istate,
158164
const char *name, int namelen,
159165
const struct pathspec_item *item);

0 commit comments

Comments
 (0)