Skip to content

Commit 861be8a

Browse files
committed
rm: integrate with sparse-index
Enable the sparse index within the `git-rm` command. The `p2000` tests demonstrate a ~92% execution time reduction for 'git rm' using a sparse index. Test HEAD~1 HEAD -------------------------------------------------------------------------- 2000.74: git rm ... (full-v3) 0.41(0.37+0.05) 0.43(0.36+0.07) +4.9% 2000.75: git rm ... (full-v4) 0.38(0.34+0.05) 0.39(0.35+0.05) +2.6% 2000.76: git rm ... (sparse-v3) 0.57(0.56+0.01) 0.05(0.05+0.00) -91.2% 2000.77: git rm ... (sparse-v4) 0.57(0.55+0.02) 0.03(0.03+0.00) -94.7% ---- Also, normalize a behavioral difference of `git-rm` under sparse-index. See related discussion [1]. `git-rm` a sparse-directory entry within a sparse-index enabled repo behaves differently from a sparse directory within a sparse-checkout enabled repo. For example, in a sparse-index repo, where 'folder1' is a sparse-directory entry, `git rm -r --sparse folder1` provides this: rm 'folder1/' Whereas in a sparse-checkout repo *without* sparse-index, doing so provides this: rm 'folder1/0/0/0' rm 'folder1/0/1' rm 'folder1/a' Because `git rm` a sparse-directory entry does not need to expand the index, therefore we should accept the current behavior, which is faster than "expand the sparse-directory entry to match the sparse-checkout situation". Modify a previous test so such difference is not considered as an error. [1] #6 (comment) Helped-by: Victoria Dye <[email protected]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Shaoxuan Yuan <[email protected]>
1 parent 1c4a85f commit 861be8a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

builtin/rm.c

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
287287
if (!index_only)
288288
setup_work_tree();
289289

290+
prepare_repo_settings(the_repository);
291+
the_repository->settings.command_requires_full_index = 0;
290292
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
291293

292294
if (read_cache() < 0)

t/perf/p2000-sparse-operations.sh

+1
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,6 @@ test_perf_on_all git blame $SPARSE_CONE/f3/a
123123
test_perf_on_all git read-tree -mu HEAD
124124
test_perf_on_all git checkout-index -f --all
125125
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
126+
test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
126127

127128
test_done

t/t1092-sparse-checkout-compatibility.sh

+17-3
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ test_expect_success 'read-tree --prefix' '
912912
test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
913913
test_all_match git status --porcelain=v2 &&
914914
915-
test_all_match git rm -rf --sparse folder1/ &&
915+
run_on_all git rm -rf --sparse folder1/ &&
916916
test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
917917
test_all_match git status --porcelain=v2 &&
918918
@@ -1874,7 +1874,7 @@ test_expect_success 'rm pathspec inside sparse definition' '
18741874
test_all_match git status --porcelain=v2
18751875
'
18761876

1877-
test_expect_failure 'rm pathspec outside sparse definition' '
1877+
test_expect_success 'rm pathspec outside sparse definition' '
18781878
init_repos &&
18791879
18801880
for file in folder1/a folder1/0/1
@@ -1914,7 +1914,7 @@ test_expect_failure 'rm pathspec outside sparse definition' '
19141914
test_sparse_match git status --porcelain=v2
19151915
'
19161916

1917-
test_expect_failure 'rm pathspec expands index when necessary' '
1917+
test_expect_success 'rm pathspec expands index when necessary' '
19181918
init_repos &&
19191919
19201920
# in-cone pathspec (do not expand)
@@ -1933,4 +1933,18 @@ test_expect_failure 'rm pathspec expands index when necessary' '
19331933
test_must_be_empty sparse-index-err
19341934
'
19351935

1936+
test_expect_success 'sparse index is not expanded: rm' '
1937+
init_repos &&
1938+
1939+
ensure_not_expanded rm deep/a &&
1940+
1941+
# test in-cone wildcard
1942+
git -C sparse-index reset --hard &&
1943+
ensure_not_expanded rm deep/* &&
1944+
1945+
# test recursive rm
1946+
git -C sparse-index reset --hard &&
1947+
ensure_not_expanded rm -r deep
1948+
'
1949+
19361950
test_done

0 commit comments

Comments
 (0)