Skip to content

Commit d76723e

Browse files
derrickstoleegitster
authored andcommitted
status: use sparse-index throughout
By testing 'git -c core.fsmonitor= status -uno', we can check for the simplest index operations that can be made sparse-aware. The necessary implementation details are already integrated with sparse-checkout, so modify command_requires_full_index to be zero for cmd_status(). In refresh_index(), we loop through the index entries to refresh their stat() information. However, sparse directories have no stat() information to populate. Ignore these entries. This allows 'git status' to no longer expand a sparse index to a full one. This is further tested by dropping the "-uno" option and adding an untracked file into the worktree. The performance test p2000-sparse-checkout-operations.sh demonstrates these improvements: Test HEAD~1 HEAD ----------------------------------------------------------------------------- 2000.2: git status (full-index-v3) 0.31(0.30+0.05) 0.31(0.29+0.06) +0.0% 2000.3: git status (full-index-v4) 0.31(0.29+0.07) 0.34(0.30+0.08) +9.7% 2000.4: git status (sparse-index-v3) 2.35(2.28+0.10) 0.04(0.04+0.05) -98.3% 2000.5: git status (sparse-index-v4) 2.35(2.24+0.15) 0.05(0.04+0.06) -97.9% Note that since HEAD~1 was expanding the sparse index by parsing trees, it was artificially slower than the full index case. Thus, the 98% improvement is misleading, and instead we should celebrate the 0.34s to 0.05s improvement of 85%. This is more indicative of the peformance gains we are expecting by using a sparse index. Note: we are dropping the assignment of core.fsmonitor here. This is not necessary for the test script as we are not altering the config any other way. Correct integration with FS Monitor will be validated in later changes. Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bf48e5a commit d76723e

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

builtin/commit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
15101510
if (argc == 2 && !strcmp(argv[1], "-h"))
15111511
usage_with_options(builtin_status_usage, builtin_status_options);
15121512

1513+
prepare_repo_settings(the_repository);
1514+
the_repository->settings.command_requires_full_index = 0;
1515+
15131516
status_init_config(&s, git_status_config);
15141517
argc = parse_options(argc, argv, prefix,
15151518
builtin_status_options,

read-cache.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,8 +1585,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
15851585
*/
15861586
preload_index(istate, pathspec, 0);
15871587
trace2_region_enter("index", "refresh", NULL);
1588-
/* TODO: audit for interaction with sparse-index. */
1589-
ensure_full_index(istate);
1588+
15901589
for (i = 0; i < istate->cache_nr; i++) {
15911590
struct cache_entry *ce, *new_entry;
15921591
int cache_errno = 0;
@@ -1601,6 +1600,13 @@ int refresh_index(struct index_state *istate, unsigned int flags,
16011600
if (ignore_skip_worktree && ce_skip_worktree(ce))
16021601
continue;
16031602

1603+
/*
1604+
* If this entry is a sparse directory, then there isn't
1605+
* any stat() information to update. Ignore the entry.
1606+
*/
1607+
if (S_ISSPARSEDIR(ce->ce_mode))
1608+
continue;
1609+
16041610
if (pathspec && !ce_path_match(istate, ce, pathspec, seen))
16051611
filtered = 1;
16061612

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,17 @@ test_expect_success 'sparse-index is expanded and converted back' '
511511
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
512512
git -C sparse-index -c core.fsmonitor="" reset --hard &&
513513
test_region index convert_to_sparse trace2.txt &&
514-
test_region index ensure_full_index trace2.txt &&
514+
test_region index ensure_full_index trace2.txt
515+
'
515516

516-
rm trace2.txt &&
517+
test_expect_success 'sparse-index is not expanded' '
518+
init_repos &&
519+
520+
rm -f trace2.txt &&
521+
echo >>sparse-index/untracked.txt &&
517522
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
518-
git -C sparse-index -c core.fsmonitor="" status -uno &&
519-
test_region index ensure_full_index trace2.txt
523+
git -C sparse-index status &&
524+
test_region ! index ensure_full_index trace2.txt
520525
'
521526

522527
test_done

0 commit comments

Comments
 (0)