check-attr: integrate with sparse-index

Set the requires-full-index to false for "check-attr". Add a test to ensure that the index is not expanded whether the files are outside or inside the sparse-checkout cone when the sparse index is enabled. The `p2000` tests demonstrate a ~63% execution time reduction for 'git check-attr' using a sparse index. Test before after ----------------------------------------------------------------------- 2000.106: git check-attr -a f2/f4/a (full-v3) 0.05 0.05 +0.0% 2000.107: git check-attr -a f2/f4/a (full-v4) 0.05 0.05 +0.0% 2000.108: git check-attr -a f2/f4/a (sparse-v3) 0.04 0.02 -50.0% 2000.109: git check-attr -a f2/f4/a (sparse-v4) 0.04 0.01 -75.0% Helped-by: Victoria Dye <vdye@github.com> Signed-off-by: Shuqi Liang <cheskaqiqi@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shuqi Liang committed Aug 11, 2023 at 10:22 UTC f9815878c16892aae7c5be11ac67200aef6e4ff6
3 files changed +19
builtin/check-attr.c
+3
@@ -122,6 +122,9 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
122 argc = parse_options(argc, argv, prefix, check_attr_options,
123 check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
124
125 + prepare_repo_settings(the_repository);
126 + the_repository->settings.command_requires_full_index = 0;
127 +
128 if (repo_read_index(the_repository) < 0) {
129 die("invalid cache");
130 }
t/perf/p2000-sparse-operations.sh
+1
@@ -134,5 +134,6 @@ test_perf_on_all git diff-files -- $SPARSE_CONE/a
134 test_perf_on_all git diff-tree HEAD
135 test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
136 test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
137 +test_perf_on_all git check-attr -a -- $SPARSE_CONE/a
138
139 test_done
t/t1092-sparse-checkout-compatibility.sh
+15
@@ -2316,4 +2316,19 @@ test_expect_failure 'diff --check with pathspec outside sparse definition' '
2316 test_all_match test_must_fail git diff --check --cached -- folder1/a
2317 '
2318
2319 +test_expect_success 'sparse-index is not expanded: check-attr' '
2320 + init_repos &&
2321 +
2322 + echo "a -crlf myAttr" >>.gitattributes &&
2323 + mkdir ./sparse-index/folder1 &&
2324 + cp ./sparse-index/a ./sparse-index/folder1/a &&
2325 + cp .gitattributes ./sparse-index/deep &&
2326 + cp .gitattributes ./sparse-index/folder1 &&
2327 +
2328 + git -C sparse-index add deep/.gitattributes &&
2329 + git -C sparse-index add --sparse folder1/.gitattributes &&
2330 + ensure_not_expanded check-attr -a --cached -- deep/a &&
2331 + ensure_not_expanded check-attr -a --cached -- folder1/a
2332 +'
2333 +
2334 test_done