From 124b05b23005437fa5fb91863bde2a8f5840e164 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Tue, 26 Apr 2022 20:43:20 +0000 Subject: 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 ":" syntax. The 'git rev-parse' output is only the OID of the object found at that location, but otherwise behaves similarly to 'git show :'. 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 Signed-off-by: Junio C Hamano --- builtin/rev-parse.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin/rev-parse.c') diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 8480a59f57..4fc6185b2d 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -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, "--")) { -- cgit 1.2.3-korg