Skip to content

Commit 08de915

Browse files
bmwillgitster
authored andcommitted
pathspec: convert find_pathspecs_matching_against_index to take an index
Convert find_pathspecs_matching_against_index to take an index parameter. In addition mark pathspec.c with NO_THE_INDEX_COMPATIBILITY_MACROS now that it doesn't use any cache macros or reference 'the_index'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2249d4d commit 08de915

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
136136
*dst++ = entry;
137137
}
138138
dir->nr = dst - dir->entries;
139-
add_pathspec_matches_against_index(pathspec, seen);
139+
add_pathspec_matches_against_index(pathspec, &the_index, seen);
140140
return seen;
141141
}
142142

@@ -418,7 +418,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
418418
int i;
419419

420420
if (!seen)
421-
seen = find_pathspecs_matching_against_index(&pathspec);
421+
seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
422422

423423
/*
424424
* file_exists() assumes exact match

builtin/check-ignore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int check_ignore(struct dir_struct *dir,
9898
* should not be ignored, in order to be consistent with
9999
* 'git status', 'git add' etc.
100100
*/
101-
seen = find_pathspecs_matching_against_index(&pathspec);
101+
seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
102102
for (i = 0; i < pathspec.nr; i++) {
103103
full_path = pathspec.items[i].match;
104104
exclude = NULL;

pathspec.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define NO_THE_INDEX_COMPATIBILITY_MACROS
12
#include "cache.h"
23
#include "dir.h"
34
#include "pathspec.h"
@@ -17,6 +18,7 @@
1718
* to use find_pathspecs_matching_against_index() instead.
1819
*/
1920
void add_pathspec_matches_against_index(const struct pathspec *pathspec,
21+
const struct index_state *istate,
2022
char *seen)
2123
{
2224
int num_unmatched = 0, i;
@@ -32,8 +34,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
3234
num_unmatched++;
3335
if (!num_unmatched)
3436
return;
35-
for (i = 0; i < active_nr; i++) {
36-
const struct cache_entry *ce = active_cache[i];
37+
for (i = 0; i < istate->cache_nr; i++) {
38+
const struct cache_entry *ce = istate->cache[i];
3739
ce_path_match(ce, pathspec, seen);
3840
}
3941
}
@@ -46,10 +48,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
4648
* nature of the "closest" (i.e. most specific) matches which each of the
4749
* given pathspecs achieves against all items in the index.
4850
*/
49-
char *find_pathspecs_matching_against_index(const struct pathspec *pathspec)
51+
char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
52+
const struct index_state *istate)
5053
{
5154
char *seen = xcalloc(pathspec->nr, 1);
52-
add_pathspec_matches_against_index(pathspec, seen);
55+
add_pathspec_matches_against_index(pathspec, istate, seen);
5356
return seen;
5457
}
5558

pathspec.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ static inline int ps_strcmp(const struct pathspec_item *item,
9696
return strcmp(s1, s2);
9797
}
9898

99-
extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec);
100-
extern void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *seen);
99+
extern void add_pathspec_matches_against_index(const struct pathspec *pathspec,
100+
const struct index_state *istate,
101+
char *seen);
102+
extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
103+
const struct index_state *istate);
101104

102105
#endif /* PATHSPEC_H */

0 commit comments

Comments
 (0)