Skip to content

Commit ede241c

Browse files
ffyuandagitster
authored andcommitted
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] ffyuanda#6 (comment) Helped-by: Victoria Dye <[email protected]> Helped-by: Derrick Stolee <[email protected]> Signed-off-by: Shaoxuan Yuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bcf96cf commit ede241c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

builtin/rm.c

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ test_expect_success 'read-tree --prefix' '
937937
test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
938938
test_all_match git status --porcelain=v2 &&
939939
940-
test_all_match git rm -rf --sparse folder1/ &&
940+
run_on_all git rm -rf --sparse folder1/ &&
941941
test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
942942
test_all_match git status --porcelain=v2 &&
943943
@@ -1899,7 +1899,7 @@ test_expect_success 'rm pathspec inside sparse definition' '
18991899
test_all_match git status --porcelain=v2
19001900
'
19011901

1902-
test_expect_failure 'rm pathspec outside sparse definition' '
1902+
test_expect_success 'rm pathspec outside sparse definition' '
19031903
init_repos &&
19041904
19051905
for file in folder1/a folder1/0/1
@@ -1939,7 +1939,7 @@ test_expect_failure 'rm pathspec outside sparse definition' '
19391939
test_sparse_match git status --porcelain=v2
19401940
'
19411941

1942-
test_expect_failure 'rm pathspec expands index when necessary' '
1942+
test_expect_success 'rm pathspec expands index when necessary' '
19431943
init_repos &&
19441944
19451945
# in-cone pathspec (do not expand)
@@ -1958,4 +1958,18 @@ test_expect_failure 'rm pathspec expands index when necessary' '
19581958
test_must_be_empty sparse-index-err
19591959
'
19601960

1961+
test_expect_success 'sparse index is not expanded: rm' '
1962+
init_repos &&
1963+
1964+
ensure_not_expanded rm deep/a &&
1965+
1966+
# test in-cone wildcard
1967+
git -C sparse-index reset --hard &&
1968+
ensure_not_expanded rm deep/* &&
1969+
1970+
# test recursive rm
1971+
git -C sparse-index reset --hard &&
1972+
ensure_not_expanded rm -r deep
1973+
'
1974+
19611975
test_done

0 commit comments

Comments
 (0)