Skip to content

Commit acdeb10

Browse files
committed
Merge branch 'ds/sparse-colon-path'
"git show :<path>" learned to work better with the sparse-index feature. * ds/sparse-colon-path: rev-parse: integrate with sparse index object-name: diagnose trees in index properly object-name: reject trees found in the index show: integrate with the sparse index t1092: add compatibility tests for 'git show'
2 parents 5a9253c + 124b05b commit acdeb10

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
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);

builtin/rev-parse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
723723
prefix = setup_git_directory();
724724
git_config(git_default_config, NULL);
725725
did_repo_setup = 1;
726+
727+
prepare_repo_settings(the_repository);
728+
the_repository->settings.command_requires_full_index = 0;
726729
}
727730

728731
if (!strcmp(arg, "--")) {

object-name.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,8 @@ static void diagnose_invalid_index_path(struct repository *r,
18321832
pos = -pos - 1;
18331833
if (pos < istate->cache_nr) {
18341834
ce = istate->cache[pos];
1835-
if (ce_namelen(ce) == namelen &&
1835+
if (!S_ISSPARSEDIR(ce->ce_mode) &&
1836+
ce_namelen(ce) == namelen &&
18361837
!memcmp(ce->name, filename, namelen))
18371838
die(_("path '%s' is in the index, but not at stage %d\n"
18381839
"hint: Did you mean ':%d:%s'?"),
@@ -1848,7 +1849,8 @@ static void diagnose_invalid_index_path(struct repository *r,
18481849
pos = -pos - 1;
18491850
if (pos < istate->cache_nr) {
18501851
ce = istate->cache[pos];
1851-
if (ce_namelen(ce) == fullname.len &&
1852+
if (!S_ISSPARSEDIR(ce->ce_mode) &&
1853+
ce_namelen(ce) == fullname.len &&
18521854
!memcmp(ce->name, fullname.buf, fullname.len))
18531855
die(_("path '%s' is in the index, but not '%s'\n"
18541856
"hint: Did you mean ':%d:%s' aka ':%d:./%s'?"),
@@ -1881,6 +1883,20 @@ static char *resolve_relative_path(struct repository *r, const char *rel)
18811883
rel);
18821884
}
18831885

1886+
static int reject_tree_in_index(struct repository *repo,
1887+
int only_to_die,
1888+
const struct cache_entry *ce,
1889+
int stage,
1890+
const char *prefix,
1891+
const char *cp)
1892+
{
1893+
if (!S_ISSPARSEDIR(ce->ce_mode))
1894+
return 0;
1895+
if (only_to_die)
1896+
diagnose_invalid_index_path(repo, stage, prefix, cp);
1897+
return -1;
1898+
}
1899+
18841900
static enum get_oid_result get_oid_with_context_1(struct repository *repo,
18851901
const char *name,
18861902
unsigned flags,
@@ -1955,9 +1971,12 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
19551971
memcmp(ce->name, cp, namelen))
19561972
break;
19571973
if (ce_stage(ce) == stage) {
1974+
free(new_path);
1975+
if (reject_tree_in_index(repo, only_to_die, ce,
1976+
stage, prefix, cp))
1977+
return -1;
19581978
oidcpy(oid, &ce->oid);
19591979
oc->mode = ce->ce_mode;
1960-
free(new_path);
19611980
return 0;
19621981
}
19631982
pos++;

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,33 @@ test_expect_success 'clean' '
12001200
test_sparse_match test_path_is_dir folder1
12011201
'
12021202

1203+
for builtin in show rev-parse
1204+
do
1205+
test_expect_success "$builtin (cached blobs/trees)" "
1206+
init_repos &&
1207+
1208+
test_all_match git $builtin :a &&
1209+
test_all_match git $builtin :deep/a &&
1210+
test_sparse_match git $builtin :folder1/a &&
1211+
1212+
# The error message differs depending on whether
1213+
# the directory exists in the worktree.
1214+
test_all_match test_must_fail git $builtin :deep/ &&
1215+
test_must_fail git -C full-checkout $builtin :folder1/ &&
1216+
test_sparse_match test_must_fail git $builtin :folder1/ &&
1217+
1218+
# Change the sparse cone for an extra case:
1219+
run_on_sparse git sparse-checkout set deep/deeper1 &&
1220+
1221+
# deep/deeper2 is a sparse directory in the sparse index.
1222+
test_sparse_match test_must_fail git $builtin :deep/deeper2/ &&
1223+
1224+
# deep/deeper2/deepest is not in the sparse index, but
1225+
# will trigger an index expansion.
1226+
test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/
1227+
"
1228+
done
1229+
12031230
test_expect_success 'submodule handling' '
12041231
init_repos &&
12051232
@@ -1448,6 +1475,15 @@ test_expect_success 'sparse index is not expanded: diff' '
14481475
ensure_not_expanded diff --cached
14491476
'
14501477

1478+
test_expect_success 'sparse index is not expanded: show and rev-parse' '
1479+
init_repos &&
1480+
1481+
ensure_not_expanded show :a &&
1482+
ensure_not_expanded show :deep/a &&
1483+
ensure_not_expanded rev-parse :a &&
1484+
ensure_not_expanded rev-parse :deep/a
1485+
'
1486+
14511487
test_expect_success 'sparse index is not expanded: update-index' '
14521488
init_repos &&
14531489

0 commit comments

Comments
 (0)