git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Raghul Nanth A <nanth.raghul@gmail.com>
To: git@vger.kernel.org
Cc: derrickstolee@github.com, vdye@github.com, nanth.raghul@gmail.com
Subject: [GSOC][PATCH v2] diff-index: enable sparse index
Date: Sat,  8 Apr 2023 16:53:42 +0530	[thread overview]
Message-ID: <20230408112342.404318-1-nanth.raghul@gmail.com> (raw)
In-Reply-To: <20230403190538.361840-1-nanth.raghul@gmail.com>

diff-index uses the run_diff_index() function to generate its diff. This
function has been made sparse-index aware in the series that led to
8d2c3732 (Merge branch 'ld/sparse-diff-blame', 2021-12-21). Hence we can
just set the requires-full-index to false for "diff-index".

Performance metrics

  Test                                                  HEAD~1            HEAD
  ----------------------------------------------------------------------------------------------
  2000.2: echo >>a && git diff-index HEAD (full-v3)     0.09(0.06+0.04)   0.09(0.07+0.03) +0.0%
  2000.3: echo >>a && git diff-index HEAD (full-v4)     0.09(0.06+0.04)   0.09(0.05+0.05) +0.0%
  2000.4: echo >>a && git diff-index HEAD (sparse-v3)   0.37(0.31+0.06)   0.01(0.02+0.03) -97.3%
  2000.5: echo >>a && git diff-index HEAD (sparse-v4)   0.30(0.26+0.05)   0.01(0.01+0.04) -96.7%
  2000.6: git diff-index HEAD **a (full-v3)             0.06(0.05+0.01)   0.06(0.06+0.01) +0.0%
  2000.7: git diff-index HEAD **a (full-v4)             0.06(0.05+0.01)   0.06(0.04+0.02) +0.0%
  2000.8: git diff-index HEAD **a (sparse-v3)           0.29(0.25+0.03)   0.01(0.01+0.00) -96.6%
  2000.9: git diff-index HEAD **a (sparse-v4)           0.37(0.34+0.02)   0.01(0.01+0.00) -97.3%
  2000.10: git diff-index --cached HEAD (full-v3)       0.05(0.03+0.01)   0.05(0.03+0.02) +0.0%
  2000.11: git diff-index --cached HEAD (full-v4)       0.05(0.03+0.01)   0.05(0.02+0.02) +0.0%
  2000.12: git diff-index --cached HEAD (sparse-v3)     0.35(0.33+0.01)   0.01(0.00+0.00) -97.1%
  2000.13: git diff-index --cached HEAD (sparse-v4)     0.35(0.32+0.02)   0.01(0.00+0.00) -97.1%
---

Sorry for the late reply. Got caught up in school work
  * Fixed commit message
  * Added check to expand index if needed (based on diff-files)
  * Added pathspec based tests

 builtin/diff-index.c                     |  9 +++++
 t/perf/p2000-sparse-operations.sh        |  3 ++
 t/t1092-sparse-checkout-compatibility.sh | 44 ++++++++++++++++++++++++
 3 files changed, 56 insertions(+)

diff --git a/builtin/diff-index.c b/builtin/diff-index.c
index 35dc9b23ee..e67cf5a1db 100644
--- a/builtin/diff-index.c
+++ b/builtin/diff-index.c
@@ -24,6 +24,14 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
 		usage(diff_cache_usage);
 
 	git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
+
+	prepare_repo_settings(the_repository);
+	the_repository->settings.command_requires_full_index = 0;
+
+	if (pathspec_needs_expanded_index(the_repository->index,
+					  &rev.diffopt.pathspec))
+		ensure_full_index(the_repository->index);
+
 	repo_init_revisions(the_repository, &rev, prefix);
 	rev.abbrev = 0;
 	prefix = precompose_argv_prefix(argc, argv, prefix);
@@ -69,6 +77,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
 		perror("repo_read_index");
 		return -1;
 	}
+
 	result = run_diff_index(&rev, option);
 	result = diff_result_code(&rev.diffopt, result);
 	release_revisions(&rev);
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index 3242cfe91a..62499d3aa8 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -125,5 +125,8 @@ 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_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
+test_perf_on_all 'echo >>a && git diff-index HEAD'
+test_perf_on_all git diff-index HEAD "**a"
+test_perf_on_all git diff-index --cached HEAD
 
 test_done
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index 801919009e..24bc716c48 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -1996,6 +1996,50 @@ test_expect_success 'sparse index is not expanded: rm' '
 	ensure_not_expanded rm -r deep
 '
 
+test_expect_success 'sparse index is not expanded: diff-index' '
+	init_repos &&
+
+	echo "new" >>sparse-index/g &&
+	git -C sparse-index add g &&
+	git -C sparse-index commit -m "dummy" &&
+	ensure_not_expanded diff-index HEAD~1 &&
+
+	echo "text" >>sparse-index/deep/a &&
+
+	ensure_not_expanded diff-index HEAD deep/a &&
+	ensure_not_expanded diff-index HEAD deep/*
+'
+test_expect_success 'diff-index pathspec expands index when necessary' '
+	init_repos &&
+
+	echo "text" >>sparse-index/deep/a &&
+
+	# pathspec that should expand index
+	! ensure_not_expanded diff-index "*/a" &&
+	! ensure_not_expanded diff-index "**a"
+'
+
+test_expect_success 'diff-index with pathspec outside sparse definition' '
+	init_repos &&
+
+	test_sparse_match test_must_fail git diff-index HEAD folder2/a
+'
+
+test_expect_success 'match all: diff-index' '
+	init_repos &&
+
+	test_all_match git diff-index HEAD &&
+	write_script edit-contents <<-\EOF &&
+	echo text >>$1
+	EOF
+	run_on_all ../edit-contents g &&
+	run_on_all git add g &&
+	run_on_all git commit -m "two" &&
+	run_on_all rm g &&
+	test_all_match git diff-index HEAD &&
+	test_all_match git diff-index --cached HEAD~1
+'
+
 test_expect_success 'grep with and --cached' '
 	init_repos &&
 
-- 
2.40.0


  parent reply	other threads:[~2023-04-08 11:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03 19:05 [GSOC][PATCH v1] diff-index: enable diff-index Raghul Nanth A
2023-04-04  0:16 ` Junio C Hamano
2023-04-05 17:53 ` Victoria Dye
2023-04-05 19:28   ` Junio C Hamano
2023-04-08 11:23 ` Raghul Nanth A [this message]
2023-04-13 21:14   ` [GSOC][PATCH v2] diff-index: enable sparse index Victoria Dye
2023-04-19 15:15     ` RAGHUL NANTH
2023-04-22 21:25       ` Shuqi Liang
2023-05-02  9:46         ` [GSOC] " Raghul Nanth A
2023-05-02 17:35           ` Victoria Dye

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=20230408112342.404318-1-nanth.raghul@gmail.com \
    --to=nanth.raghul@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).