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>
Brandon Williams committed
Jun 12, 2017 at 15:14 UTC
6510ae173a8630e39a225f15031a7975547979ec
1 file changed
+8
-7
builtin/ls-files.c
+8
-7
@@ -380,30 +380,31 @@ static void show_files(struct dir_struct *dir)
380
/*
381
* Prune the index to only contain stuff starting with "prefix"
382
*/
383
-static void prune_cache(const char *prefix, size_t prefixlen)
383
+static void prune_index(struct index_state *istate,
384
+ const char *prefix, size_t prefixlen)
385
{
386
int pos;
387
unsigned int first, last;
388
389
if (!prefix)
390
return;
390
- pos = cache_name_pos(prefix, prefixlen);
391
+ pos = index_name_pos(istate, prefix, prefixlen);
392
if (pos < 0)
393
pos = -pos-1;
394
first = pos;
394
- last = active_nr;
395
+ last = istate->cache_nr;
396
while (last > first) {
397
int next = (last + first) >> 1;
397
- const struct cache_entry *ce = active_cache[next];
398
+ const struct cache_entry *ce = istate->cache[next];
399
if (!strncmp(ce->name, prefix, prefixlen)) {
400
first = next+1;
401
continue;
402
}
403
last = next;
404
}
404
- memmove(active_cache, active_cache + pos,
405
+ memmove(istate->cache, istate->cache + pos,
406
(last - pos) * sizeof(struct cache_entry *));
406
- active_nr = last - pos;
407
+ istate->cache_nr = last - pos;
408
}
409
410
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)
662
max_prefix = common_prefix(&pathspec);
663
max_prefix_len = get_common_prefix_len(max_prefix);
664
664
- prune_cache(max_prefix, max_prefix_len);
665
+ prune_index(&the_index, max_prefix, max_prefix_len);
666
667
/* Treat unmatching pathspec elements as errors */
668
if (pathspec.nr && error_unmatch)