Skip to content

Commit

Permalink
rm: integrate with sparse-index
Browse files Browse the repository at this point in the history
Enable the sparse index within the `git-rm` command.

The `p2000` tests demonstrate a ~96% execution time reduction for
'git rm' using a sparse index.

Test                                     before  after
-------------------------------------------------------------
2000.74: git rm -f f2/f4/a (full-v3)     0.66    0.88 +33.0%
2000.75: git rm -f f2/f4/a (full-v4)     0.67    0.75 +12.0%
2000.76: git rm -f f2/f4/a (sparse-v3)   1.99    0.08 -96.0%
2000.77: git rm -f f2/f4/a (sparse-v4)   2.06    0.07 -96.6%

----
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)

Signed-off-by: Shaoxuan Yuan <[email protected]>
  • Loading branch information
ffyuanda committed Aug 3, 2022
1 parent 5c76cdc commit 4247a64
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions builtin/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
if (!index_only)
setup_work_tree();

prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);

if (read_cache() < 0)
Expand Down
1 change: 1 addition & 0 deletions t/perf/p2000-sparse-operations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@ test_perf_on_all git blame $SPARSE_CONE/f3/a
test_perf_on_all git read-tree -mu HEAD
test_perf_on_all git checkout-index -f --all
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
test_perf_on_all git rm -f $SPARSE_CONE/a

test_done
6 changes: 3 additions & 3 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ test_expect_success 'read-tree --prefix' '
test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
test_all_match git status --porcelain=v2 &&
test_all_match git rm -rf --sparse folder1/ &&
run_on_all git rm -rf --sparse folder1/ &&
test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
test_all_match git status --porcelain=v2 &&
Expand Down Expand Up @@ -1870,7 +1870,7 @@ test_expect_success 'rm pathspec inside sparse definition' '
test_all_match git status --porcelain=v2
'

test_expect_failure 'rm pathspec outside sparse definition' '
test_expect_success 'rm pathspec outside sparse definition' '
init_repos &&
for file in folder1/a folder1/0/1
Expand Down Expand Up @@ -1910,7 +1910,7 @@ test_expect_failure 'rm pathspec outside sparse definition' '
test_sparse_match git status --porcelain=v2
'

test_expect_failure 'sparse index is not expanded: rm' '
test_expect_success 'sparse index is not expanded: rm' '
init_repos &&
ensure_not_expanded rm deep/a &&
Expand Down

0 comments on commit 4247a64

Please sign in to comment.