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>
Brandon Williams committed
May 11, 2017 at 15:04 UTC
08de9151a8a67f29a3a5a36931298237d78ca736
4 files changed
+15
-9
builtin/add.c
+2
-2
@@ -136,7 +136,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
136
*dst++ = entry;
137
}
138
dir->nr = dst - dir->entries;
139
- add_pathspec_matches_against_index(pathspec, seen);
139
+ add_pathspec_matches_against_index(pathspec, &the_index, seen);
140
return seen;
141
}
142
@@ -418,7 +418,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
418
int i;
419
420
if (!seen)
421
- seen = find_pathspecs_matching_against_index(&pathspec);
421
+ seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
422
423
/*
424
* file_exists() assumes exact match
builtin/check-ignore.c
+1
-1
@@ -98,7 +98,7 @@ static int check_ignore(struct dir_struct *dir,
98
* should not be ignored, in order to be consistent with
99
* 'git status', 'git add' etc.
100
*/
101
- seen = find_pathspecs_matching_against_index(&pathspec);
101
+ seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
102
for (i = 0; i < pathspec.nr; i++) {
103
full_path = pathspec.items[i].match;
104
exclude = NULL;
pathspec.c
+7
-4
@@ -1,3 +1,4 @@
1
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
2
#include "cache.h"
3
#include "dir.h"
4
#include "pathspec.h"
@@ -17,6 +18,7 @@
18
* to use find_pathspecs_matching_against_index() instead.
19
*/
20
void add_pathspec_matches_against_index(const struct pathspec *pathspec,
21
+ const struct index_state *istate,
22
char *seen)
23
{
24
int num_unmatched = 0, i;
@@ -32,8 +34,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
34
num_unmatched++;
35
if (!num_unmatched)
36
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];
39
ce_path_match(ce, pathspec, seen);
40
}
41
}
@@ -46,10 +48,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
48
* nature of the "closest" (i.e. most specific) matches which each of the
49
* given pathspecs achieves against all items in the index.
50
*/
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)
53
{
54
char *seen = xcalloc(pathspec->nr, 1);
52
- add_pathspec_matches_against_index(pathspec, seen);
55
+ add_pathspec_matches_against_index(pathspec, istate, seen);
56
return seen;
57
}
58
pathspec.h
+5
-2
@@ -96,7 +96,10 @@ static inline int ps_strcmp(const struct pathspec_item *item,
96
return strcmp(s1, s2);
97
}
98
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);
104
105
#endif /* PATHSPEC_H */