ls-files: ensure full index

Before iterating over all cache entries, ensure that a sparse index is expanded to a full one to avoid missing files. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Apr 1, 2021 at 01:49 UTC 42f44e84eb3be06f463ebc33baa2fc91423f4470
1 file changed +4
builtin/ls-files.c
+4
@@ -317,6 +317,8 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
317
318 if (!(show_cached || show_stage || show_deleted || show_modified))
319 return;
320 + /* TODO: audit for interaction with sparse-index. */
321 + ensure_full_index(repo->index);
322 for (i = 0; i < repo->index->cache_nr; i++) {
323 const struct cache_entry *ce = repo->index->cache[i];
324 struct stat st;
@@ -494,6 +496,8 @@ void overlay_tree_on_index(struct index_state *istate,
496 die("bad tree-ish %s", tree_name);
497
498 /* Hoist the unmerged entries up to stage #3 to make room */
499 + /* TODO: audit for interaction with sparse-index. */
500 + ensure_full_index(istate);
501 for (i = 0; i < istate->cache_nr; i++) {
502 struct cache_entry *ce = istate->cache[i];
503 if (!ce_stage(ce))