From: Derrick Stolee <dstolee@xxxxxxxxxxxxx> Disable command_requires_full_index for 'git add'. This does not require any additional removals of ensure_full_index(). The main reason is that 'git add' discovers changes based on the pathspec and the worktree itself. These are then inserted into the index directly, and calls to index_name_pos() or index_file_exists() already call expand_to_path() at the appropriate time to support a sparse-index. Add a test to check that 'git add -A' and 'git add <file>' does not expand the index at all, as long as <file> is not within a sparse directory. This does not help the global 'git add .' case. We can measure the improvement using p2000-sparse-operations.sh with these results: Test HEAD~1 HEAD ------------------------------------------------------------------------------ 2000.6: git add -A (full-index-v3) 1.35(1.00+0.20) 1.33(0.98+0.19) -1.5% 2000.7: git add -A (full-index-v4) 1.25(0.97+0.17) 1.23(0.96+0.16) -1.6% 2000.8: git add -A (sparse-index-v3) 2.38(2.28+0.13) 0.06(0.04+0.08) -97.5% 2000.9: git add -A (sparse-index-v4) 2.39(2.25+0.18) 0.06(0.04+0.07) -97.5% While the 97% improvement seems impressive, it's important to recognize that previously we had significant overhead for expanding the sparse-index. Comparing to the full index case, 'git add -A' goes from 1.33s to 0.06s, which is "only" a 95% improvement. Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- builtin/add.c | 3 +++ t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/builtin/add.c b/builtin/add.c index 58ee3f954ef7..0572d0344065 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -526,6 +526,9 @@ int cmd_add(int argc, const char **argv, const char *prefix) add_new_files = !take_worktree_changes && !refresh_only && !add_renormalize; require_pathspec = !(take_worktree_changes || (0 < addremove_explicit)); + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); /* diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index b937d7096afd..c210dba78067 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -459,6 +459,18 @@ test_expect_success 'sparse-index is not expanded' ' echo >>sparse-index/untracked.txt && GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ git -C sparse-index status && + test_region ! index ensure_full_index trace2.txt && + + rm trace2.txt && + echo >>sparse-index/README.md && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index add -A && + test_region ! index ensure_full_index trace2.txt && + + rm trace2.txt && + echo >>sparse-index/extra.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index add extra.txt && test_region ! index ensure_full_index trace2.txt ' -- gitgitgadget