Skip to content

Commit 63a75b5

Browse files
derrickstoleevdye
authored andcommitted
Merge pull request git-for-windows#470: Sparse Index: integrate with git show
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.
2 parents 76e4526 + f6ebbee commit 63a75b5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,34 @@ test_expect_success 'clean' '
11911191
test_sparse_match test_path_is_dir folder1
11921192
'
11931193

1194+
test_expect_success 'show (cached blobs/trees)' '
1195+
init_repos &&
1196+
1197+
test_all_match git show :a &&
1198+
test_all_match git show :deep/a &&
1199+
test_sparse_match git show :folder1/a &&
1200+
1201+
# Asking "git show" for directories in the index
1202+
# does not work as implemented. The error message is
1203+
# different for a full checkout and a sparse checkout
1204+
# when the directory is outside of the cone.
1205+
test_all_match test_must_fail git show :deep/ &&
1206+
test_must_fail git -C full-checkout 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
1220+
'
1221+
11941222
test_expect_success 'submodule handling' '
11951223
init_repos &&
11961224
@@ -1305,6 +1333,9 @@ test_expect_success 'sparse-index is not expanded' '
13051333
echo >>sparse-index/untracked.txt &&
13061334
ensure_not_expanded add . &&
13071335
1336+
ensure_not_expanded show :a &&
1337+
ensure_not_expanded show :deep/a &&
1338+
13081339
echo >>sparse-index/a &&
13091340
ensure_not_expanded stash &&
13101341
ensure_not_expanded stash list &&

0 commit comments

Comments
 (0)