git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
To: git@vger.kernel.org
Cc: vdye@github.com, derrickstolee@github.com,
	Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
Subject: [PATCH v2 4/4] rm: integrate with sparse-index
Date: Sun,  7 Aug 2022 12:13:35 +0800	[thread overview]
Message-ID: <20220807041335.1790658-5-shaoxuan.yuan02@gmail.com> (raw)
In-Reply-To: <20220807041335.1790658-1-shaoxuan.yuan02@gmail.com>

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] https://github.com/ffyuanda/git/pull/6#discussion_r934861398

Helped-by: Victoria Dye <vdye@github.com>
Helped-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
---
 builtin/rm.c                             |  2 ++
 t/perf/p2000-sparse-operations.sh        |  1 +
 t/t1092-sparse-checkout-compatibility.sh | 20 +++++++++++++++++---
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 58ed924f0d..b6ba859fe4 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -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)
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index c181110a43..fce8151d41 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -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 && git checkout HEAD -- $SPARSE_CONE/a"
 
 test_done
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index 94464cf911..68ded9063b 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -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 &&
 
@@ -1874,7 +1874,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
@@ -1914,7 +1914,7 @@ test_expect_failure 'rm pathspec outside sparse definition' '
 	test_sparse_match git status --porcelain=v2
 '
 
-test_expect_failure 'rm pathspec expands index when necessary' '
+test_expect_success 'rm pathspec expands index when necessary' '
 	init_repos &&
 
 	# in-cone pathspec (do not expand)
@@ -1933,4 +1933,18 @@ test_expect_failure 'rm pathspec expands index when necessary' '
 	test_must_be_empty sparse-index-err
 '
 
+test_expect_success 'sparse index is not expanded: rm' '
+	init_repos &&
+
+	ensure_not_expanded rm deep/a &&
+
+	# test in-cone wildcard
+	git -C sparse-index reset --hard &&
+	ensure_not_expanded rm deep/* &&
+
+	# test recursive rm
+	git -C sparse-index reset --hard &&
+	ensure_not_expanded rm -r deep
+'
+
 test_done
-- 
2.37.0


  parent reply	other threads:[~2022-08-07  4:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03  4:51 [PATCH v1 0/4] rm: integrate with sparse-index Shaoxuan Yuan
2022-08-03  4:51 ` [PATCH v1 1/4] t1092: add tests for `git-rm` Shaoxuan Yuan
2022-08-03 14:32   ` Derrick Stolee
2022-08-03  4:51 ` [PATCH v1 2/4] pathspec.h: move pathspec_needs_expanded_index() from reset.c to here Shaoxuan Yuan
2022-08-03 14:35   ` Derrick Stolee
2022-08-05  7:53     ` Shaoxuan Yuan
2022-08-03  4:51 ` [PATCH v1 3/4] rm: expand the index only when necessary Shaoxuan Yuan
2022-08-03 14:40   ` Derrick Stolee
2022-08-05  8:07     ` Shaoxuan Yuan
2022-08-03  4:51 ` [PATCH v1 4/4] rm: integrate with sparse-index Shaoxuan Yuan
2022-08-04 14:48   ` Derrick Stolee
2022-08-06  3:18     ` Shaoxuan Yuan
2022-08-07  4:13 ` [PATCH v2 0/4] " Shaoxuan Yuan
2022-08-07  4:13   ` [PATCH v2 1/4] t1092: add tests for `git-rm` Shaoxuan Yuan
2022-08-10 12:47     ` Derrick Stolee
2022-08-07  4:13   ` [PATCH v2 2/4] pathspec.h: move pathspec_needs_expanded_index() from reset.c to here Shaoxuan Yuan
2022-08-07  4:13   ` [PATCH v2 3/4] rm: expand the index only when necessary Shaoxuan Yuan
2022-08-10  0:24     ` Victoria Dye
2022-08-07  4:13   ` Shaoxuan Yuan [this message]
2022-08-08 17:24   ` [PATCH v2 0/4] rm: integrate with sparse-index Junio C Hamano
2022-08-08 17:51     ` Victoria Dye
2022-08-08 19:01       ` Junio C Hamano
2022-08-10  0:27   ` Victoria Dye
2022-08-10  0:31     ` Shaoxuan Yuan
2022-08-12 18:36     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220807041335.1790658-5-shaoxuan.yuan02@gmail.com \
    --to=shaoxuan.yuan02@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@vger.kernel.org \
    --cc=vdye@github.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).