pathspec: convert find_pathspecs_matching_against_index to take an index
authorBrandon Williams <bmwill@google.com>
Thu, 11 May 2017 22:04:27 +0000 (15:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 May 2017 05:23:46 +0000 (14:23 +0900)
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>
builtin/add.c
builtin/check-ignore.c
pathspec.c
pathspec.h
index 86770d6af4773470cef19ef230a6f0eb8c246a3a..0365a520989047b5ecff4f5cc0253705b60ff45b 100644 (file)
@@ -136,7 +136,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
                        *dst++ = entry;
        }
        dir->nr = dst - dir->entries;
-       add_pathspec_matches_against_index(pathspec, seen);
+       add_pathspec_matches_against_index(pathspec, &the_index, seen);
        return seen;
 }
 
@@ -418,7 +418,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                int i;
 
                if (!seen)
-                       seen = find_pathspecs_matching_against_index(&pathspec);
+                       seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
 
                /*
                 * file_exists() assumes exact match
index 91040a4b04a9c5ee2bbdb086dab8225763808321..7629018a561eb07712dd8ae7fe14bf669159bbf6 100644 (file)
@@ -98,7 +98,7 @@ static int check_ignore(struct dir_struct *dir,
         * should not be ignored, in order to be consistent with
         * 'git status', 'git add' etc.
         */
-       seen = find_pathspecs_matching_against_index(&pathspec);
+       seen = find_pathspecs_matching_against_index(&pathspec, &the_index);
        for (i = 0; i < pathspec.nr; i++) {
                full_path = pathspec.items[i].match;
                exclude = NULL;
index 1e5df2316e6624f6e9dd9b6aaa25a874b5409525..828405021fca4214585e1d46b65f604d14e61143 100644 (file)
@@ -1,3 +1,4 @@
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "dir.h"
 #include "pathspec.h"
@@ -17,6 +18,7 @@
  * to use find_pathspecs_matching_against_index() instead.
  */
 void add_pathspec_matches_against_index(const struct pathspec *pathspec,
+                                       const struct index_state *istate,
                                        char *seen)
 {
        int num_unmatched = 0, i;
@@ -32,8 +34,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
                        num_unmatched++;
        if (!num_unmatched)
                return;
-       for (i = 0; i < active_nr; i++) {
-               const struct cache_entry *ce = active_cache[i];
+       for (i = 0; i < istate->cache_nr; i++) {
+               const struct cache_entry *ce = istate->cache[i];
                ce_path_match(ce, pathspec, seen);
        }
 }
@@ -46,10 +48,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
  * nature of the "closest" (i.e. most specific) matches which each of the
  * given pathspecs achieves against all items in the index.
  */
-char *find_pathspecs_matching_against_index(const struct pathspec *pathspec)
+char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
+                                           const struct index_state *istate)
 {
        char *seen = xcalloc(pathspec->nr, 1);
-       add_pathspec_matches_against_index(pathspec, seen);
+       add_pathspec_matches_against_index(pathspec, istate, seen);
        return seen;
 }
 
index 6671b95770f5abf74fd97bd86e447bd20b04502e..60e6500401e687bc0d764c38c5d8b4928b7bfde8 100644 (file)
@@ -96,7 +96,10 @@ static inline int ps_strcmp(const struct pathspec_item *item,
                return strcmp(s1, s2);
 }
 
-extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec);
-extern void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *seen);
+extern void add_pathspec_matches_against_index(const struct pathspec *pathspec,
+                                              const struct index_state *istate,
+                                              char *seen);
+extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec,
+                                                  const struct index_state *istate);
 
 #endif /* PATHSPEC_H */