Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 576e0b6

Browse files
committed
Merge branch 'ds/ls-files-lazy-unsparse'
"git ls-files <pathspec>..." should not necessarily have to expand the index fully if a sparsified directory is excluded by the pathspec; the code is taught to expand the index on demand to avoid this. * ds/ls-files-lazy-unsparse: ls-files: conditionally leave index sparse
2 parents 4a7ebb9 + 681f26b commit 576e0b6

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

builtin/ls-files.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,21 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
414414
if (!(show_cached || show_stage || show_deleted || show_modified))
415415
return;
416416

417-
if (!show_sparse_dirs)
418-
ensure_full_index(repo->index);
419-
420417
for (i = 0; i < repo->index->cache_nr; i++) {
421418
const struct cache_entry *ce = repo->index->cache[i];
422419
struct stat st;
423420
int stat_err;
424421

422+
if (S_ISSPARSEDIR(ce->ce_mode) && !show_sparse_dirs) {
423+
/*
424+
* This is the first time we've hit a sparse dir,
425+
* so expansion will leave the first 'i' entries
426+
* alone.
427+
*/
428+
ensure_full_index(repo->index);
429+
ce = repo->index->cache[i];
430+
}
431+
425432
construct_fullname(&fullname, repo, ce);
426433

427434
if ((dir->flags & DIR_SHOW_IGNORED) &&

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ test_expect_success 'sparse-index is not expanded' '
15061506
ensure_not_expanded reset --hard &&
15071507
ensure_not_expanded restore -s rename-out-to-out -- deep/deeper1 &&
15081508
1509+
ensure_not_expanded ls-files deep/deeper1 &&
1510+
15091511
echo >>sparse-index/README.md &&
15101512
ensure_not_expanded add -A &&
15111513
echo >>sparse-index/extra.txt &&
@@ -1607,6 +1609,17 @@ test_expect_success 'describe tested on all' '
16071609
test_all_match git describe --dirty
16081610
'
16091611

1612+
test_expect_success 'ls-files filtering and expansion' '
1613+
init_repos &&
1614+
1615+
# This filtering will hit a sparse directory midway
1616+
# through the iteration.
1617+
test_all_match git ls-files deep &&
1618+
1619+
# This pathspec will filter the index to only a sparse
1620+
# directory.
1621+
test_all_match git ls-files folder1
1622+
'
16101623

16111624
test_expect_success 'sparse-index is not expanded: describe' '
16121625
init_repos &&

0 commit comments

Comments
 (0)