Skip to content

Commit db3cb9f

Browse files
committed
Merge branch 'ds/sparse-colon-path' into seen
source: <[email protected]> * 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 82b9eae + 124b05b commit db3cb9f

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
@@ -668,6 +668,11 @@ int cmd_show(int argc, const char **argv, const char *prefix)
668668
init_log_defaults();
669669
git_config(git_log_config, NULL);
670670

671+
if (the_repository->gitdir) {
672+
prepare_repo_settings(the_repository);
673+
the_repository->settings.command_requires_full_index = 0;
674+
}
675+
671676
memset(&match_all, 0, sizeof(match_all));
672677
repo_init_revisions(the_repository, &rev, prefix);
673678
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
@@ -1836,7 +1836,8 @@ static void diagnose_invalid_index_path(struct repository *r,
18361836
pos = -pos - 1;
18371837
if (pos < istate->cache_nr) {
18381838
ce = istate->cache[pos];
1839-
if (ce_namelen(ce) == namelen &&
1839+
if (!S_ISSPARSEDIR(ce->ce_mode) &&
1840+
ce_namelen(ce) == namelen &&
18401841
!memcmp(ce->name, filename, namelen))
18411842
die(_("path '%s' is in the index, but not at stage %d\n"
18421843
"hint: Did you mean ':%d:%s'?"),
@@ -1852,7 +1853,8 @@ static void diagnose_invalid_index_path(struct repository *r,
18521853
pos = -pos - 1;
18531854
if (pos < istate->cache_nr) {
18541855
ce = istate->cache[pos];
1855-
if (ce_namelen(ce) == fullname.len &&
1856+
if (!S_ISSPARSEDIR(ce->ce_mode) &&
1857+
ce_namelen(ce) == fullname.len &&
18561858
!memcmp(ce->name, fullname.buf, fullname.len))
18571859
die(_("path '%s' is in the index, but not '%s'\n"
18581860
"hint: Did you mean ':%d:%s' aka ':%d:./%s'?"),
@@ -1885,6 +1887,20 @@ static char *resolve_relative_path(struct repository *r, const char *rel)
18851887
rel);
18861888
}
18871889

1890+
static int reject_tree_in_index(struct repository *repo,
1891+
int only_to_die,
1892+
const struct cache_entry *ce,
1893+
int stage,
1894+
const char *prefix,
1895+
const char *cp)
1896+
{
1897+
if (!S_ISSPARSEDIR(ce->ce_mode))
1898+
return 0;
1899+
if (only_to_die)
1900+
diagnose_invalid_index_path(repo, stage, prefix, cp);
1901+
return -1;
1902+
}
1903+
18881904
static enum get_oid_result get_oid_with_context_1(struct repository *repo,
18891905
const char *name,
18901906
unsigned flags,
@@ -1959,9 +1975,12 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
19591975
memcmp(ce->name, cp, namelen))
19601976
break;
19611977
if (ce_stage(ce) == stage) {
1978+
free(new_path);
1979+
if (reject_tree_in_index(repo, only_to_die, ce,
1980+
stage, prefix, cp))
1981+
return -1;
19621982
oidcpy(oid, &ce->oid);
19631983
oc->mode = ce->ce_mode;
1964-
free(new_path);
19651984
return 0;
19661985
}
19671986
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)