Skip to content

Commit

Permalink
Merge pull request #470: Sparse Index: integrate with git show
Browse files Browse the repository at this point in the history
As we roll out the sparse index feature, here is a command that I see being used more frequently than other non-integrated commands. (For example, `git mv` is used much less frequently.)

Since the index expansion only happens when using `git show :<path>` to indicate that we are looking for a cached value, this is very likely being used by a tool and not directly by users. However, the performance slowdown is around 10x (0.4s to 4.1s at p50).

The change here is simple, and we can catch up the performance in the next release. There is a slightly odd behavior change when asking for a directory that now "works" but did not work at all before. See the test change in the second commit for details.
  • Loading branch information
derrickstolee authored and dscho committed Jun 17, 2022
2 parents 99f0af2 + 798011f commit 7f8458a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,34 @@ 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_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' '
init_repos &&
Expand Down Expand Up @@ -1305,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 &&
Expand Down

0 comments on commit 7f8458a

Please sign in to comment.