Skip to content

ls-files: conditionally leave index sparse #1955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,21 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
if (!(show_cached || show_stage || show_deleted || show_modified))
return;

if (!show_sparse_dirs)
ensure_full_index(repo->index);

for (i = 0; i < repo->index->cache_nr; i++) {
const struct cache_entry *ce = repo->index->cache[i];
struct stat st;
int stat_err;

if (S_ISSPARSEDIR(ce->ce_mode) && !show_sparse_dirs) {
/*
* This is the first time we've hit a sparse dir,
* so expansion will leave the first 'i' entries
* alone.
*/
ensure_full_index(repo->index);
ce = repo->index->cache[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering whether we'd want to avoid calling ensure_full_index() multiple times, but it seems that it returns early if istate->sparse_index == INDEX_EXPANDED, so it's safe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But also we will never have S_ISSPARSEDIR() true after expansion.

}

construct_fullname(&fullname, repo, ce);

if ((dir->flags & DIR_SHOW_IGNORED) &&
Expand Down
13 changes: 13 additions & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,8 @@ test_expect_success 'sparse-index is not expanded' '
ensure_not_expanded reset --hard &&
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&

ensure_not_expanded ls-files deep/deeper1 &&

echo >>sparse-index/README.md &&
ensure_not_expanded add -A &&
echo >>sparse-index/extra.txt &&
Expand Down Expand Up @@ -1607,6 +1609,17 @@ test_expect_success 'describe tested on all' '
test_all_match git describe --dirty
'

test_expect_success 'ls-files filtering and expansion' '
init_repos &&

# This filtering will hit a sparse directory midway
# through the iteration.
test_all_match git ls-files deep &&

# This pathspec will filter the index to only a sparse
# directory.
test_all_match git ls-files folder1
'

test_expect_success 'sparse-index is not expanded: describe' '
init_repos &&
Expand Down
Loading