]> git.ipfire.org Git - thirdparty/git.git/commitdiff
check-attr: integrate with sparse-index
authorShuqi Liang <cheskaqiqi@gmail.com>
Fri, 11 Aug 2023 14:22:11 +0000 (10:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Aug 2023 16:44:52 +0000 (09:44 -0700)
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>
builtin/check-attr.c
t/perf/p2000-sparse-operations.sh
t/t1092-sparse-checkout-compatibility.sh

index b22ff748c3e20819887084f1175015a9a6078815..c1da1d184e9f6e24687f751bc67f88641f7083b0 100644 (file)
@@ -122,6 +122,9 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, check_attr_options,
                             check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
 
+       prepare_repo_settings(the_repository);
+       the_repository->settings.command_requires_full_index = 0;
+
        if (repo_read_index(the_repository) < 0) {
                die("invalid cache");
        }
index 96ed3e1d69881541c82bdaf8c7f6b6fd8af97ef5..39e92b0841437bee9cbd939de6e216fae81a7ff2 100755 (executable)
@@ -134,5 +134,6 @@ test_perf_on_all git diff-files -- $SPARSE_CONE/a
 test_perf_on_all git diff-tree HEAD
 test_perf_on_all git diff-tree HEAD -- $SPARSE_CONE/a
 test_perf_on_all "git worktree add ../temp && git worktree remove ../temp"
+test_perf_on_all git check-attr -a -- $SPARSE_CONE/a
 
 test_done
index dc84b3e2e17fe289d029d26add6ece7f394274cf..2a4f35e98450f8ab499f11a1bafa777a82101136 100755 (executable)
@@ -2316,4 +2316,19 @@ test_expect_failure 'diff --check with pathspec outside sparse definition' '
        test_all_match test_must_fail git diff --check --cached -- folder1/a
 '
 
+test_expect_success 'sparse-index is not expanded: check-attr' '
+       init_repos &&
+
+       echo "a -crlf myAttr" >>.gitattributes &&
+       mkdir ./sparse-index/folder1 &&
+       cp ./sparse-index/a ./sparse-index/folder1/a &&
+       cp .gitattributes ./sparse-index/deep &&
+       cp .gitattributes ./sparse-index/folder1 &&
+
+       git -C sparse-index add deep/.gitattributes &&
+       git -C sparse-index add --sparse folder1/.gitattributes &&
+       ensure_not_expanded check-attr -a --cached -- deep/a &&
+       ensure_not_expanded check-attr -a --cached -- folder1/a
+'
+
 test_done