Skip to content

Commit 124b05b

Browse files
derrickstoleegitster
authored andcommitted
rev-parse: integrate with sparse index
It is not obvious that the 'git rev-parse' builtin would use the sparse index, but it is possible to parse paths out of the index using the ":<path>" syntax. The 'git rev-parse' output is only the OID of the object found at that location, but otherwise behaves similarly to 'git show :<path>'. This includes the failure conditions on directories and the error messages depending on whether a path is in the worktree or not. The only code change required is to change the command_requires_full_index setting in builtin/rev-parse.c, and we can re-use many existing 'git show' tests for the rev-parse case. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4925adb commit 124b05b

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

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, "--")) {

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,29 +1151,32 @@ test_expect_success 'clean' '
11511151
test_sparse_match test_path_is_dir folder1
11521152
'
11531153

1154-
test_expect_success 'show (cached blobs/trees)' '
1155-
init_repos &&
1154+
for builtin in show rev-parse
1155+
do
1156+
test_expect_success "$builtin (cached blobs/trees)" "
1157+
init_repos &&
11561158
1157-
test_all_match git show :a &&
1158-
test_all_match git show :deep/a &&
1159-
test_sparse_match git show :folder1/a &&
1159+
test_all_match git $builtin :a &&
1160+
test_all_match git $builtin :deep/a &&
1161+
test_sparse_match git $builtin :folder1/a &&
11601162
1161-
# The error message differs depending on whether
1162-
# the directory exists in the worktree.
1163-
test_all_match test_must_fail git show :deep/ &&
1164-
test_must_fail git -C full-checkout show :folder1/ &&
1165-
test_sparse_match test_must_fail git show :folder1/ &&
1163+
# The error message differs depending on whether
1164+
# the directory exists in the worktree.
1165+
test_all_match test_must_fail git $builtin :deep/ &&
1166+
test_must_fail git -C full-checkout $builtin :folder1/ &&
1167+
test_sparse_match test_must_fail git $builtin :folder1/ &&
11661168
1167-
# Change the sparse cone for an extra case:
1168-
run_on_sparse git sparse-checkout set deep/deeper1 &&
1169+
# Change the sparse cone for an extra case:
1170+
run_on_sparse git sparse-checkout set deep/deeper1 &&
11691171
1170-
# deep/deeper2 is a sparse directory in the sparse index.
1171-
test_sparse_match test_must_fail git show :deep/deeper2/ &&
1172+
# deep/deeper2 is a sparse directory in the sparse index.
1173+
test_sparse_match test_must_fail git $builtin :deep/deeper2/ &&
11721174
1173-
# deep/deeper2/deepest is not in the sparse index, but
1174-
# will trigger an index expansion.
1175-
test_sparse_match test_must_fail git show :deep/deeper2/deepest/
1176-
'
1175+
# deep/deeper2/deepest is not in the sparse index, but
1176+
# will trigger an index expansion.
1177+
test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/
1178+
"
1179+
done
11771180

11781181
test_expect_success 'submodule handling' '
11791182
init_repos &&
@@ -1396,11 +1399,13 @@ test_expect_success 'sparse index is not expanded: diff' '
13961399
ensure_not_expanded diff --cached
13971400
'
13981401

1399-
test_expect_success 'sparse index is not expanded: show' '
1402+
test_expect_success 'sparse index is not expanded: show and rev-parse' '
14001403
init_repos &&
14011404
14021405
ensure_not_expanded show :a &&
1403-
ensure_not_expanded show :deep/a
1406+
ensure_not_expanded show :deep/a &&
1407+
ensure_not_expanded rev-parse :a &&
1408+
ensure_not_expanded rev-parse :deep/a
14041409
'
14051410

14061411
test_expect_success 'sparse index is not expanded: update-index' '

0 commit comments

Comments
 (0)