ls-files: convert prune_cache to take an index
authorBrandon Williams <bmwill@google.com>
Mon, 12 Jun 2017 22:14:04 +0000 (15:14 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Jun 2017 18:40:51 +0000 (11:40 -0700)
Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-files.c
index 762257f3997ef91f77623bc4e1bd0fb8164d2756..b1626b13b43f3a69b35bc242c30a28b51a855306 100644 (file)
@@ -380,30 +380,31 @@ static void show_files(struct dir_struct *dir)
 /*
  * Prune the index to only contain stuff starting with "prefix"
  */
-static void prune_cache(const char *prefix, size_t prefixlen)
+static void prune_index(struct index_state *istate,
+                       const char *prefix, size_t prefixlen)
 {
        int pos;
        unsigned int first, last;
 
        if (!prefix)
                return;
-       pos = cache_name_pos(prefix, prefixlen);
+       pos = index_name_pos(istate, prefix, prefixlen);
        if (pos < 0)
                pos = -pos-1;
        first = pos;
-       last = active_nr;
+       last = istate->cache_nr;
        while (last > first) {
                int next = (last + first) >> 1;
-               const struct cache_entry *ce = active_cache[next];
+               const struct cache_entry *ce = istate->cache[next];
                if (!strncmp(ce->name, prefix, prefixlen)) {
                        first = next+1;
                        continue;
                }
                last = next;
        }
-       memmove(active_cache, active_cache + pos,
+       memmove(istate->cache, istate->cache + pos,
                (last - pos) * sizeof(struct cache_entry *));
-       active_nr = last - pos;
+       istate->cache_nr = last - pos;
 }
 
 static int get_common_prefix_len(const char *common_prefix)
@@ -661,7 +662,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
                max_prefix = common_prefix(&pathspec);
        max_prefix_len = get_common_prefix_len(max_prefix);
 
-       prune_cache(max_prefix, max_prefix_len);
+       prune_index(&the_index, max_prefix, max_prefix_len);
 
        /* Treat unmatching pathspec elements as errors */
        if (pathspec.nr && error_unmatch)