summaryrefslogtreecommitdiff
path: root/builtin/rev-parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/rev-parse.c')
-rw-r--r--builtin/rev-parse.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 8401b4d7ab..7b3711cf34 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -3,7 +3,10 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
+
#define USE_THE_REPOSITORY_VARIABLE
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "builtin.h"
#include "abspath.h"
@@ -705,11 +708,12 @@ int cmd_rev_parse(int argc,
struct object_id oid;
unsigned int flags = 0;
const char *name = NULL;
- struct object_context unused;
struct strbuf buf = STRBUF_INIT;
int seen_end_of_options = 0;
enum format_type format = FORMAT_DEFAULT;
+ show_usage_if_asked(argc, argv, builtin_rev_parse_usage);
+
if (argc > 1 && !strcmp("--parseopt", argv[1]))
return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -729,7 +733,7 @@ int cmd_rev_parse(int argc,
/* No options; just report on whether we're in a git repo or not. */
if (argc == 1) {
setup_git_directory();
- git_config(git_default_config, NULL);
+ repo_config(the_repository, git_default_config, NULL);
return 0;
}
@@ -764,7 +768,7 @@ int cmd_rev_parse(int argc,
/* The rest of the options require a git repository. */
if (!did_repo_setup) {
prefix = setup_git_directory();
- git_config(git_default_config, NULL);
+ repo_config(the_repository, git_default_config, NULL);
did_repo_setup = 1;
prepare_repo_settings(the_repository);
@@ -784,8 +788,8 @@ int cmd_rev_parse(int argc,
if (!strcmp(arg, "--git-path")) {
if (!argv[i + 1])
die(_("--git-path requires an argument"));
- strbuf_reset(&buf);
- print_path(git_path("%s", argv[i + 1]), prefix,
+ print_path(repo_git_path_replace(the_repository, &buf,
+ "%s", argv[i + 1]), prefix,
format,
DEFAULT_RELATIVE_IF_SHARED);
i++;
@@ -1078,7 +1082,7 @@ int cmd_rev_parse(int argc,
die(_("Could not read the index"));
if (the_repository->index->split_index) {
const struct object_id *oid = &the_repository->index->split_index->base_oid;
- const char *path = git_path("sharedindex.%s", oid_to_hex(oid));
+ const char *path = repo_git_path_replace(the_repository, &buf, "sharedindex.%s", oid_to_hex(oid));
print_path(path, prefix, format, DEFAULT_RELATIVE);
}
continue;
@@ -1103,11 +1107,20 @@ int cmd_rev_parse(int argc,
const char *val = arg ? arg : "storage";
if (strcmp(val, "storage") &&
+ strcmp(val, "compat") &&
strcmp(val, "input") &&
strcmp(val, "output"))
die(_("unknown mode for --show-object-format: %s"),
arg);
- puts(the_hash_algo->name);
+
+ if (!strcmp(val, "compat")) {
+ if (the_repository->compat_hash_algo)
+ puts(the_repository->compat_hash_algo->name);
+ else
+ putchar('\n');
+ } else {
+ puts(the_hash_algo->name);
+ }
continue;
}
if (!strcmp(arg, "--show-ref-format")) {
@@ -1136,9 +1149,8 @@ int cmd_rev_parse(int argc,
name++;
type = REVERSED;
}
- if (!get_oid_with_context(the_repository, name,
- flags, &oid, &unused)) {
- object_context_release(&unused);
+ if (!repo_get_oid_with_flags(the_repository, name, &oid,
+ flags)) {
if (output_algo)
repo_oid_to_algop(the_repository, &oid,
output_algo, &oid);
@@ -1148,7 +1160,6 @@ int cmd_rev_parse(int argc,
show_rev(type, &oid, name);
continue;
}
- object_context_release(&unused);
if (verify)
die_no_single_rev(quiet);
if (has_dashdash)