From eb4ce78ce05504019f38eed6f758358ebb8720fe Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 29 Nov 2021 15:18:56 -0500 Subject: [PATCH 1/2] t1092: add compatibility tests for 'git show' Signed-off-by: Derrick Stolee --- t/t1092-sparse-checkout-compatibility.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 03a75a8a98019e..cb78e43a321a8c 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1191,6 +1191,22 @@ test_expect_success 'clean' ' test_sparse_match test_path_is_dir folder1 ' +test_expect_success 'show (cached blobs/trees)' ' + init_repos && + + test_all_match git show :a && + test_all_match git show :deep/a && + test_sparse_match git show :folder1/a && + + # Asking "git show" for directories in the index + # does not work as implemented. The error message is + # different for a full checkout and a sparse checkout + # when the directory is outside of the cone. + test_all_match test_must_fail git show :deep/ && + test_must_fail git -C full-checkout show :folder1/ && + test_sparse_match test_must_fail git show :folder1/ +' + test_expect_success 'submodule handling' ' init_repos && From 798011f0535c7f46777625cd7ac8a5a06b8e4d74 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 29 Nov 2021 15:22:33 -0500 Subject: [PATCH 2/2] 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 --- builtin/log.c | 5 +++++ t/t1092-sparse-checkout-compatibility.sh | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/builtin/log.c b/builtin/log.c index 9084d0e90d7bf6..f4c00de7de2697 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -669,6 +669,11 @@ int cmd_show(int argc, const char **argv, const char *prefix) init_log_defaults(); git_config(git_log_config, NULL); + if (the_repository->gitdir) { + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + } + memset(&match_all, 0, sizeof(match_all)); repo_init_revisions(the_repository, &rev, prefix); git_config(grep_config, &rev.grep_filter); diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index cb78e43a321a8c..debdf56cb686f8 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1204,7 +1204,19 @@ test_expect_success 'show (cached blobs/trees)' ' # when the directory is outside of the cone. test_all_match test_must_fail git show :deep/ && test_must_fail git -C full-checkout show :folder1/ && - test_sparse_match test_must_fail git show :folder1/ + test_must_fail git -C sparse-checkout show :folder1/ && + + # The sparse index actually has "folder1" inside, so + # "git show :folder1/" succeeds when it did not before. + git -C sparse-index show :folder1/ >actual && + git -C sparse-index show HEAD:folder1 >expect && + + # The output of "git show" includes the way we + # referenced the objects, so strip that out. + test_line_count = 4 actual && + tail -n 2 actual >actual-trunc && + tail -n 2 expect >expect-trunc && + test_cmp expect-trunc actual-trunc ' test_expect_success 'submodule handling' ' @@ -1321,6 +1333,9 @@ test_expect_success 'sparse-index is not expanded' ' echo >>sparse-index/untracked.txt && ensure_not_expanded add . && + ensure_not_expanded show :a && + ensure_not_expanded show :deep/a && + echo >>sparse-index/a && ensure_not_expanded stash && ensure_not_expanded stash list &&