summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-06-12 15:14:04 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-13 11:40:51 -0700
commit6510ae173a8630e39a225f15031a7975547979ec (patch)
tree9354000349f208fd66c142fe3468f52ceb75422f
parent1d35e3bf056b508f4ece3875f9d2851be5fcd3d4 (diff)
downloadgit-6510ae173a8630e39a225f15031a7975547979ec.tar.gz
ls-files: convert prune_cache to take an index
Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/ls-files.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 762257f399..b1626b13b4 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -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)