Skip to content

Commit f6ebbee

Browse files
derrickstoleevdye
authored andcommitted
show: integrate with the sparse index
The 'git show' command can take an input to request the state of an object in the index. This can lead to parsing the index in order to load a specific file entry. Without the change presented here, a sparse index would expand to a full one, taking much longer than usual to access a simple file. There is one behavioral change that happens here, though: we now can find a sparse directory entry within the index! Commands that previously failed because we could not find an entry in the worktree or index now succeed because we _do_ find an entry in the index. There might be more work to do to make other situations succeed when looking for an indexed tree, perhaps by looking at or updating the cache-tree extension as needed. These situations include having a full index or asking for a directory that is within the sparse-checkout cone (and hence is not a sparse directory entry in the index). Signed-off-by: Derrick Stolee <[email protected]>
1 parent 3dde05a commit f6ebbee

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

builtin/log.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ int cmd_show(int argc, const char **argv, const char *prefix)
669669
init_log_defaults();
670670
git_config(git_log_config, NULL);
671671

672+
if (the_repository->gitdir) {
673+
prepare_repo_settings(the_repository);
674+
the_repository->settings.command_requires_full_index = 0;
675+
}
676+
672677
memset(&match_all, 0, sizeof(match_all));
673678
repo_init_revisions(the_repository, &rev, prefix);
674679
git_config(grep_config, &rev.grep_filter);

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,19 @@ test_expect_success 'show (cached blobs/trees)' '
12041204
# when the directory is outside of the cone.
12051205
test_all_match test_must_fail git show :deep/ &&
12061206
test_must_fail git -C full-checkout show :folder1/ &&
1207-
test_sparse_match test_must_fail git show :folder1/
1207+
test_must_fail git -C sparse-checkout show :folder1/ &&
1208+
1209+
# The sparse index actually has "folder1" inside, so
1210+
# "git show :folder1/" succeeds when it did not before.
1211+
git -C sparse-index show :folder1/ >actual &&
1212+
git -C sparse-index show HEAD:folder1 >expect &&
1213+
1214+
# The output of "git show" includes the way we
1215+
# referenced the objects, so strip that out.
1216+
test_line_count = 4 actual &&
1217+
tail -n 2 actual >actual-trunc &&
1218+
tail -n 2 expect >expect-trunc &&
1219+
test_cmp expect-trunc actual-trunc
12081220
'
12091221

12101222
test_expect_success 'submodule handling' '
@@ -1321,6 +1333,9 @@ test_expect_success 'sparse-index is not expanded' '
13211333
echo >>sparse-index/untracked.txt &&
13221334
ensure_not_expanded add . &&
13231335
1336+
ensure_not_expanded show :a &&
1337+
ensure_not_expanded show :deep/a &&
1338+
13241339
echo >>sparse-index/a &&
13251340
ensure_not_expanded stash &&
13261341
ensure_not_expanded stash list &&

0 commit comments

Comments
 (0)