1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-07 15:06:08 +02:00

Merge branch 'ds/sparse-colon-path' into next

"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'
This commit is contained in:
Junio C Hamano 2022-05-13 14:31:59 -07:00
commit f1740d248a
4 changed files with 66 additions and 3 deletions

View File

@ -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);

View File

@ -723,6 +723,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
prefix = setup_git_directory();
git_config(git_default_config, NULL);
did_repo_setup = 1;
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
}
if (!strcmp(arg, "--")) {

View File

@ -1832,7 +1832,8 @@ static void diagnose_invalid_index_path(struct repository *r,
pos = -pos - 1;
if (pos < istate->cache_nr) {
ce = istate->cache[pos];
if (ce_namelen(ce) == namelen &&
if (!S_ISSPARSEDIR(ce->ce_mode) &&
ce_namelen(ce) == namelen &&
!memcmp(ce->name, filename, namelen))
die(_("path '%s' is in the index, but not at stage %d\n"
"hint: Did you mean ':%d:%s'?"),
@ -1848,7 +1849,8 @@ static void diagnose_invalid_index_path(struct repository *r,
pos = -pos - 1;
if (pos < istate->cache_nr) {
ce = istate->cache[pos];
if (ce_namelen(ce) == fullname.len &&
if (!S_ISSPARSEDIR(ce->ce_mode) &&
ce_namelen(ce) == fullname.len &&
!memcmp(ce->name, fullname.buf, fullname.len))
die(_("path '%s' is in the index, but not '%s'\n"
"hint: Did you mean ':%d:%s' aka ':%d:./%s'?"),
@ -1881,6 +1883,20 @@ static char *resolve_relative_path(struct repository *r, const char *rel)
rel);
}
static int reject_tree_in_index(struct repository *repo,
int only_to_die,
const struct cache_entry *ce,
int stage,
const char *prefix,
const char *cp)
{
if (!S_ISSPARSEDIR(ce->ce_mode))
return 0;
if (only_to_die)
diagnose_invalid_index_path(repo, stage, prefix, cp);
return -1;
}
static enum get_oid_result get_oid_with_context_1(struct repository *repo,
const char *name,
unsigned flags,
@ -1955,9 +1971,12 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
memcmp(ce->name, cp, namelen))
break;
if (ce_stage(ce) == stage) {
free(new_path);
if (reject_tree_in_index(repo, only_to_die, ce,
stage, prefix, cp))
return -1;
oidcpy(oid, &ce->oid);
oc->mode = ce->ce_mode;
free(new_path);
return 0;
}
pos++;

View File

@ -1200,6 +1200,33 @@ test_expect_success 'clean' '
test_sparse_match test_path_is_dir folder1
'
for builtin in show rev-parse
do
test_expect_success "$builtin (cached blobs/trees)" "
init_repos &&
test_all_match git $builtin :a &&
test_all_match git $builtin :deep/a &&
test_sparse_match git $builtin :folder1/a &&
# The error message differs depending on whether
# the directory exists in the worktree.
test_all_match test_must_fail git $builtin :deep/ &&
test_must_fail git -C full-checkout $builtin :folder1/ &&
test_sparse_match test_must_fail git $builtin :folder1/ &&
# Change the sparse cone for an extra case:
run_on_sparse git sparse-checkout set deep/deeper1 &&
# deep/deeper2 is a sparse directory in the sparse index.
test_sparse_match test_must_fail git $builtin :deep/deeper2/ &&
# deep/deeper2/deepest is not in the sparse index, but
# will trigger an index expansion.
test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/
"
done
test_expect_success 'submodule handling' '
init_repos &&
@ -1448,6 +1475,15 @@ test_expect_success 'sparse index is not expanded: diff' '
ensure_not_expanded diff --cached
'
test_expect_success 'sparse index is not expanded: show and rev-parse' '
init_repos &&
ensure_not_expanded show :a &&
ensure_not_expanded show :deep/a &&
ensure_not_expanded rev-parse :a &&
ensure_not_expanded rev-parse :deep/a
'
test_expect_success 'sparse index is not expanded: update-index' '
init_repos &&