]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/rev-parse.c
The fifth batch
[thirdparty/git.git] / builtin / rev-parse.c
index 181c703d4c00bcce1f1715f1a8913fad0892828d..2db047fff46471ec37594a69a168e562b2afad4c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) Linus Torvalds, 2005
  */
-#define USE_THE_INDEX_VARIABLE
+
 #include "builtin.h"
 #include "abspath.h"
 #include "config.h"
@@ -25,6 +25,7 @@
 #include "submodule.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "object-file-convert.h"
 
 #define DO_REVS                1
 #define DO_NOREV       2
@@ -159,8 +160,9 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
                        case 1: /* happy */
                                if (abbrev_ref) {
                                        char *old = full;
-                                       full = shorten_unambiguous_ref(full,
-                                               abbrev_ref_strict);
+                                       full = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+                                                                           full,
+                                                                           abbrev_ref_strict);
                                        free(old);
                                }
                                show_with_type(type, full);
@@ -598,9 +600,12 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
 static void handle_ref_opt(const char *pattern, const char *prefix)
 {
        if (pattern)
-               for_each_glob_ref_in(show_reference, pattern, prefix, NULL);
+               refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
+                                         show_reference, pattern, prefix,
+                                         NULL);
        else
-               for_each_ref_in(prefix, show_reference, NULL);
+               refs_for_each_ref_in(get_main_ref_store(the_repository),
+                                    prefix, show_reference, NULL);
        clear_ref_exclusions(&ref_excludes);
 }
 
@@ -676,6 +681,8 @@ static void print_path(const char *path, const char *prefix, enum format_type fo
 int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 {
        int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
+       const struct git_hash_algo *output_algo = NULL;
+       const struct git_hash_algo *compat = NULL;
        int did_repo_setup = 0;
        int has_dashdash = 0;
        int output_prefix = 0;
@@ -747,6 +754,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 
                        prepare_repo_settings(the_repository);
                        the_repository->settings.command_requires_full_index = 0;
+                       compat = the_repository->compat_hash_algo;
                }
 
                if (!strcmp(arg, "--")) {
@@ -834,6 +842,22 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                flags |= GET_OID_QUIETLY;
                                continue;
                        }
+                       if (opt_with_value(arg, "--output-object-format", &arg)) {
+                               if (!arg)
+                                       die(_("no object format specified"));
+                               if (!strcmp(arg, the_hash_algo->name) ||
+                                   !strcmp(arg, "storage")) {
+                                       flags |= GET_OID_HASH_ANY;
+                                       output_algo = the_hash_algo;
+                                       continue;
+                               }
+                               else if (compat && !strcmp(arg, compat->name)) {
+                                       flags |= GET_OID_HASH_ANY;
+                                       output_algo = compat;
+                                       continue;
+                               }
+                               else die(_("unsupported object format: %s"), arg);
+                       }
                        if (opt_with_value(arg, "--short", &arg)) {
                                filter &= ~(DO_FLAGS|DO_NOREV);
                                verify = 1;
@@ -878,18 +902,25 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                                continue;
                        }
                        if (!strcmp(arg, "--all")) {
-                               for_each_ref(show_reference, NULL);
+                               refs_for_each_ref(get_main_ref_store(the_repository),
+                                                 show_reference, NULL);
                                clear_ref_exclusions(&ref_excludes);
                                continue;
                        }
                        if (skip_prefix(arg, "--disambiguate=", &arg)) {
-                               repo_for_each_abbrev(the_repository, arg,
+                               repo_for_each_abbrev(the_repository, arg, the_hash_algo,
                                                     show_abbrev, NULL);
                                continue;
                        }
                        if (!strcmp(arg, "--bisect")) {
-                               for_each_fullref_in("refs/bisect/bad", show_reference, NULL);
-                               for_each_fullref_in("refs/bisect/good", anti_reference, NULL);
+                               refs_for_each_fullref_in(get_main_ref_store(the_repository),
+                                                        "refs/bisect/bad",
+                                                        NULL, show_reference,
+                                                        NULL);
+                               refs_for_each_fullref_in(get_main_ref_store(the_repository),
+                                                        "refs/bisect/good",
+                                                        NULL, anti_reference,
+                                                        NULL);
                                continue;
                        }
                        if (opt_with_value(arg, "--branches", &arg)) {
@@ -1029,8 +1060,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                        if (!strcmp(arg, "--shared-index-path")) {
                                if (repo_read_index(the_repository) < 0)
                                        die(_("Could not read the index"));
-                               if (the_index.split_index) {
-                                       const struct object_id *oid = &the_index.split_index->base_oid;
+                               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));
                                        print_path(path, prefix, format, DEFAULT_RELATIVE);
                                }
@@ -1091,6 +1122,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
                }
                if (!get_oid_with_context(the_repository, name,
                                          flags, &oid, &unused)) {
+                       if (output_algo)
+                               repo_oid_to_algop(the_repository, &oid,
+                                                 output_algo, &oid);
                        if (verify)
                                revs_count++;
                        else