Skip to content

Commit d26c8dd

Browse files
derrickstoleeldennington
authored andcommitted
Merge pull request microsoft#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 764a7d4 + 6ec5e27 commit d26c8dd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

builtin/log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
648648
init_log_defaults();
649649
git_config(git_log_config, NULL);
650650

651+
prepare_repo_settings(the_repository);
652+
the_repository->settings.command_requires_full_index = 0;
653+
651654
memset(&match_all, 0, sizeof(match_all));
652655
repo_init_revisions(the_repository, &rev, prefix);
653656
rev.diff = 1;

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,34 @@ test_expect_success 'clean' '
12611261
test_sparse_match test_path_is_dir folder1
12621262
'
12631263

1264+
test_expect_success 'show (cached blobs/trees)' '
1265+
init_repos &&
1266+
1267+
test_all_match git show :a &&
1268+
test_all_match git show :deep/a &&
1269+
test_sparse_match git show :folder1/a &&
1270+
1271+
# Asking "git show" for directories in the index
1272+
# does not work as implemented. The error message is
1273+
# different for a full checkout and a sparse checkout
1274+
# when the directory is outside of the cone.
1275+
test_all_match test_must_fail git show :deep/ &&
1276+
test_must_fail git -C full-checkout show :folder1/ &&
1277+
test_must_fail git -C sparse-checkout show :folder1/ &&
1278+
1279+
# The sparse index actually has "folder1" inside, so
1280+
# "git show :folder1/" succeeds when it did not before.
1281+
git -C sparse-index show :folder1/ >actual &&
1282+
git -C sparse-index show HEAD:folder1 >expect &&
1283+
1284+
# The output of "git show" includes the way we
1285+
# referenced the objects, so strip that out.
1286+
test_line_count = 4 actual &&
1287+
tail -n 2 actual >actual-trunc &&
1288+
tail -n 2 expect >expect-trunc &&
1289+
test_cmp expect-trunc actual-trunc
1290+
'
1291+
12641292
test_expect_success 'submodule handling' '
12651293
init_repos &&
12661294

0 commit comments

Comments
 (0)