summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLessley Dennington <lessleydennington@gmail.com>2021-12-06 15:56:01 +0000
committerJunio C Hamano <gitster@pobox.com>2021-12-06 09:55:06 -0800
commitadd4c864b60766174ad4f74ba7be17e66d61ef16 (patch)
tree1ebac752f4baef2473965a434a5b2d651684a574
parent51ba65b5c355a835fb0d83ee88dc7276dccb66a4 (diff)
blame: enable and test the sparse index
Enable the sparse index for the 'git blame' command. The index was already not expanded with this command, so the most interesting thing to do is to add tests that verify that 'git blame' behaves correctly when the sparse index is enabled and that its performance improves. More specifically, these cases are: 1. The index is not expanded for 'blame' when given paths in the sparse checkout cone at multiple levels. 2. Performance measurably improves for 'blame' with sparse index when given paths in the sparse checkout cone at multiple levels. The `p2000` tests demonstrate a ~60% execution time reduction when running 'blame' for a file two levels deep and and a ~30% execution time reduction for a file three levels deep. Test before after ---------------------------------------------------------------- 2000.62: git blame f2/f4/a (full-v3) 0.31 0.32 +3.2% 2000.63: git blame f2/f4/a (full-v4) 0.29 0.31 +6.9% 2000.64: git blame f2/f4/a (sparse-v3) 0.55 0.23 -58.2% 2000.65: git blame f2/f4/a (sparse-v4) 0.57 0.23 -59.6% 2000.66: git blame f2/f4/f3/a (full-v3) 0.77 0.85 +10.4% 2000.67: git blame f2/f4/f3/a (full-v4) 0.78 0.81 +3.8% 2000.68: git blame f2/f4/f3/a (sparse-v3) 1.07 0.72 -32.7% 2000.99: git blame f2/f4/f3/a (sparse-v4) 1.05 0.73 -30.5% We do not include paths outside the sparse checkout cone because blame does not support blaming files that are not present in the working directory. This is true in both sparse and full checkouts. Signed-off-by: Lessley Dennington <lessleydennington@gmail.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/blame.c3
-rwxr-xr-xt/perf/p2000-sparse-operations.sh2
-rwxr-xr-xt/t1092-sparse-checkout-compatibility.sh49
3 files changed, 43 insertions, 11 deletions
diff --git a/builtin/blame.c b/builtin/blame.c
index 641523ff9a..33e411d220 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -940,6 +940,9 @@ parse_done:
revs.diffopt.flags.follow_renames = 0;
argc = parse_options_end(&ctx);
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
if (incremental || (output_option & OUTPUT_PORCELAIN)) {
if (show_progress > 0)
die(_("--progress can't be used with --incremental or porcelain formats"));
diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index 5cf9462738..cb777c74a2 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -115,5 +115,7 @@ test_perf_on_all git reset --hard
test_perf_on_all git reset -- does-not-exist
test_perf_on_all git diff
test_perf_on_all git diff --cached
+test_perf_on_all git blame $SPARSE_CONE/a
+test_perf_on_all git blame $SPARSE_CONE/f3/a
test_done
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index e6885d2340..f65bd7a92f 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -472,21 +472,36 @@ test_expect_success 'log with pathspec outside sparse definition' '
test_expect_success 'blame with pathspec inside sparse definition' '
init_repos &&
- test_all_match git blame a &&
- test_all_match git blame deep/a &&
- test_all_match git blame deep/deeper1/a &&
- test_all_match git blame deep/deeper1/deepest/a
+ for file in a \
+ deep/a \
+ deep/deeper1/a \
+ deep/deeper1/deepest/a
+ do
+ test_all_match git blame $file
+ done
'
-# TODO: blame currently does not support blaming files outside of the
-# sparse definition. It complains that the file doesn't exist locally.
-test_expect_failure 'blame with pathspec outside sparse definition' '
+# Without a revision specified, blame will error if passed any file that
+# is not present in the working directory (even if the file is tracked).
+# Here we just verify that this is also true with sparse checkouts.
+test_expect_success 'blame with pathspec outside sparse definition' '
init_repos &&
+ test_sparse_match git sparse-checkout set &&
- test_all_match git blame folder1/a &&
- test_all_match git blame folder2/a &&
- test_all_match git blame deep/deeper2/a &&
- test_all_match git blame deep/deeper2/deepest/a
+ for file in a \
+ deep/a \
+ deep/deeper1/a \
+ deep/deeper1/deepest/a
+ do
+ test_sparse_match test_must_fail git blame $file &&
+ cat >expect <<-EOF &&
+ fatal: Cannot lstat '"'"'$file'"'"': No such file or directory
+ EOF
+ # We compare sparse-checkout-err and sparse-index-err in
+ # `test_sparse_match`. Given we know they are the same, we
+ # only check the content of sparse-index-err here.
+ test_cmp expect sparse-index-err
+ done
'
test_expect_success 'checkout and reset (mixed)' '
@@ -937,6 +952,18 @@ test_expect_success 'sparse index is not expanded: diff' '
ensure_not_expanded diff --cached
'
+test_expect_success 'sparse index is not expanded: blame' '
+ init_repos &&
+
+ for file in a \
+ deep/a \
+ deep/deeper1/a \
+ deep/deeper1/deepest/a
+ do
+ ensure_not_expanded blame $file
+ done
+'
+
# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
# in this scenario, but it shouldn't.
test_expect_success 'reset mixed and checkout orphan' '