Skip to content

Commit f981587

Browse files
Cheskaqiqigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Shuqi Liang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4723ae1 commit f981587

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

builtin/check-attr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
122122
argc = parse_options(argc, argv, prefix, check_attr_options,
123123
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
124124

125+
prepare_repo_settings(the_repository);
126+
the_repository->settings.command_requires_full_index = 0;
127+
125128
if (repo_read_index(the_repository) < 0) {
126129
die("invalid cache");
127130
}

t/perf/p2000-sparse-operations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,6 @@ test_perf_on_all git diff-files -- $SPARSE_CONE/a
134134
test_perf_on_all git diff-tree HEAD
135135
test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
136136
test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
137+
test_perf_on_all git check-attr -a -- $SPARSE_CONE/a
137138

138139
test_done

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,4 +2316,19 @@ test_expect_failure 'diff --check with pathspec outside sparse definition' '
23162316
test_all_match test_must_fail git diff --check --cached -- folder1/a
23172317
'
23182318

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+
23192334
test_done

0 commit comments

Comments
 (0)