Git 2.23
[gitweb.git] / builtin / show-ref.c
index ab8e0dc4142d8f2525641c3bf3f211c142578d9d..6456da70cc2c4d6a86c2466c483dd815b15bbb45 100644 (file)
@@ -1,6 +1,8 @@
 #include "builtin.h"
 #include "cache.h"
+#include "config.h"
 #include "refs.h"
+#include "object-store.h"
 #include "object.h"
 #include "tag.h"
 #include "string-list.h"
@@ -22,10 +24,14 @@ static void show_one(const char *refname, const struct object_id *oid)
        const char *hex;
        struct object_id peeled;
 
+       if (!has_object_file(oid))
+               die("git show-ref: bad ref %s (%s)", refname,
+                   oid_to_hex(oid));
+
        if (quiet)
                return;
 
-       hex = find_unique_abbrev(oid->hash, abbrev);
+       hex = find_unique_abbrev(oid, abbrev);
        if (hash_only)
                printf("%s\n", hex);
        else
@@ -34,8 +40,8 @@ static void show_one(const char *refname, const struct object_id *oid)
        if (!deref_tags)
                return;
 
-       if (!peel_ref(refname, peeled.hash)) {
-               hex = find_unique_abbrev(peeled.hash, abbrev);
+       if (!peel_ref(refname, &peeled)) {
+               hex = find_unique_abbrev(&peeled, abbrev);
                printf("%s %s^{}\n", hex, refname);
        }
 }
@@ -65,9 +71,6 @@ static int show_ref(const char *refname, const struct object_id *oid,
                                continue;
                        if (len == reflen)
                                goto match;
-                       /* "--verify" requires an exact match */
-                       if (verify)
-                               continue;
                        if (refname[reflen - len - 1] == '/')
                                goto match;
                }
@@ -77,14 +80,6 @@ static int show_ref(const char *refname, const struct object_id *oid,
 match:
        found_match++;
 
-       /* This changes the semantics slightly that even under quiet we
-        * detect and return error if the repository is corrupt and
-        * ref points at a nonexistent object.
-        */
-       if (!has_sha1_file(oid->hash))
-               die("git show-ref: bad ref %s (%s)", refname,
-                   oid_to_hex(oid));
-
        show_one(refname, oid);
 
        return 0;
@@ -157,6 +152,7 @@ static int hash_callback(const struct option *opt, const char *arg, int unset)
 static int exclude_existing_callback(const struct option *opt, const char *arg,
                                     int unset)
 {
+       BUG_ON_OPT_NEG(unset);
        exclude_arg = 1;
        *(const char **)opt->value = arg;
        return 0;
@@ -187,6 +183,8 @@ static const struct option show_ref_options[] = {
 
 int cmd_show_ref(int argc, const char **argv, const char *prefix)
 {
+       git_config(git_default_config, NULL);
+
        argc = parse_options(argc, argv, prefix, show_ref_options,
                             show_ref_usage, 0);
 
@@ -204,7 +202,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
                        struct object_id oid;
 
                        if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
-                           !read_ref(*pattern, oid.hash)) {
+                           !read_ref(*pattern, &oid)) {
                                show_one(*pattern, &oid);
                        }
                        else if (!quiet)