Skip to content

Commit e65b0c7

Browse files
klylesatepicgitster
authored andcommitted
builtin/cat-file: mark 'git cat-file' sparse-index compatible
This change affects how 'git cat-file' works with the index when specifying an object with the ":<path>" syntax (which will give file contents from the index). 'git cat-file' expands a sparse index to a full index any time contents are requested from the index by specifying an object with the ":<path>" syntax. This is true even when the requested file is part of the sparse index, and results in much slower 'git cat-file' operations when working within the sparse index. Mark 'git cat-file' as not needing a full index, so that you only pay the cost of expanding the sparse index to a full index when you request a file outside of the sparse index. Add tests to ensure both that: - 'git cat-file' returns the correct file contents whether or not the file is in the sparse index - 'git cat-file' expands to the full index any time you request something outside of the sparse index Signed-off-by: Kevin Lyles <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68c5759 commit e65b0c7

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

builtin/cat-file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
10471047
if (batch.buffer_output < 0)
10481048
batch.buffer_output = batch.all_objects;
10491049

1050+
prepare_repo_settings(the_repository);
1051+
the_repository->settings.command_requires_full_index = 0;
1052+
10501053
/* Return early if we're in batch mode? */
10511054
if (batch.enabled) {
10521055
if (opt_cw)

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,4 +2358,40 @@ test_expect_success 'advice.sparseIndexExpanded' '
23582358
grep "The sparse index is expanding to a full index" err
23592359
'
23602360

2361+
test_expect_success 'cat-file -p' '
2362+
init_repos &&
2363+
echo "new content" >>full-checkout/deep/a &&
2364+
echo "new content" >>sparse-checkout/deep/a &&
2365+
echo "new content" >>sparse-index/deep/a &&
2366+
run_on_all git add deep/a &&
2367+
2368+
test_all_match git cat-file -p :deep/a &&
2369+
ensure_not_expanded cat-file -p :deep/a &&
2370+
test_all_match git cat-file -p :folder1/a &&
2371+
ensure_expanded cat-file -p :folder1/a
2372+
'
2373+
2374+
test_expect_success 'cat-file --batch' '
2375+
init_repos &&
2376+
echo "new content" >>full-checkout/deep/a &&
2377+
echo "new content" >>sparse-checkout/deep/a &&
2378+
echo "new content" >>sparse-index/deep/a &&
2379+
run_on_all git add deep/a &&
2380+
2381+
echo ":deep/a" >in &&
2382+
test_all_match git cat-file --batch <in &&
2383+
ensure_not_expanded cat-file --batch <in &&
2384+
2385+
echo ":folder1/a" >in &&
2386+
test_all_match git cat-file --batch <in &&
2387+
ensure_expanded cat-file --batch <in &&
2388+
2389+
cat >in <<-\EOF &&
2390+
:deep/a
2391+
:folder1/a
2392+
EOF
2393+
test_all_match git cat-file --batch <in &&
2394+
ensure_expanded cat-file --batch <in
2395+
'
2396+
23612397
test_done

0 commit comments

Comments
 (0)