ident.c: add support for IPv6
[gitweb.git] / builtin / show-ref.c
index 87806ad5b088f5c905757a4fab3c3499ec20a308..131ef28e5cb5d0a08bc00a7ad99e137bdd44eb66 100644 (file)
@@ -7,8 +7,8 @@
 #include "parse-options.h"
 
 static const char * const show_ref_usage[] = {
-       N_("git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [pattern*] "),
-       N_("git show-ref --exclude-existing[=pattern] < ref-list"),
+       N_("git show-ref [-q | --quiet] [--verify] [--head] [-d | --dereference] [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [<pattern>...]"),
+       N_("git show-ref --exclude-existing[=<pattern>] < <ref-list>"),
        NULL
 };
 
@@ -17,19 +17,20 @@ static int deref_tags, show_head, tags_only, heads_only, found_match, verify,
 static const char **pattern;
 static const char *exclude_existing_arg;
 
-static void show_one(const char *refname, const unsigned char *sha1)
+static void show_one(const char *refname, const struct object_id *oid)
 {
-       const char *hex = find_unique_abbrev(sha1, abbrev);
+       const char *hex = find_unique_abbrev(oid->hash, abbrev);
        if (hash_only)
                printf("%s\n", hex);
        else
                printf("%s %s\n", hex, refname);
 }
 
-static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
+static int show_ref(const char *refname, const struct object_id *oid,
+                   int flag, void *cbdata)
 {
        const char *hex;
-       unsigned char peeled[20];
+       struct object_id peeled;
 
        if (show_head && !strcmp(refname, "HEAD"))
                goto match;
@@ -37,8 +38,8 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
        if (tags_only || heads_only) {
                int match;
 
-               match = heads_only && !prefixcmp(refname, "refs/heads/");
-               match |= tags_only && !prefixcmp(refname, "refs/tags/");
+               match = heads_only && starts_with(refname, "refs/heads/");
+               match |= tags_only && starts_with(refname, "refs/tags/");
                if (!match)
                        return 0;
        }
@@ -69,26 +70,27 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo
         * detect and return error if the repository is corrupt and
         * ref points at a nonexistent object.
         */
-       if (!has_sha1_file(sha1))
+       if (!has_sha1_file(oid->hash))
                die("git show-ref: bad ref %s (%s)", refname,
-                   sha1_to_hex(sha1));
+                   oid_to_hex(oid));
 
        if (quiet)
                return 0;
 
-       show_one(refname, sha1);
+       show_one(refname, oid);
 
        if (!deref_tags)
                return 0;
 
-       if (!peel_ref(refname, peeled)) {
-               hex = find_unique_abbrev(peeled, abbrev);
+       if (!peel_ref(refname, peeled.hash)) {
+               hex = find_unique_abbrev(peeled.hash, abbrev);
                printf("%s %s^{}\n", hex, refname);
        }
        return 0;
 }
 
-static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
+static int add_existing(const char *refname, const struct object_id *oid,
+                       int flag, void *cbdata)
 {
        struct string_list *list = (struct string_list *)cbdata;
        string_list_insert(list, refname);
@@ -165,16 +167,15 @@ static int help_callback(const struct option *opt, const char *arg, int unset)
 }
 
 static const struct option show_ref_options[] = {
-       OPT_BOOLEAN(0, "tags", &tags_only, N_("only show tags (can be combined with heads)")),
-       OPT_BOOLEAN(0, "heads", &heads_only, N_("only show heads (can be combined with tags)")),
-       OPT_BOOLEAN(0, "verify", &verify, N_("stricter reference checking, "
+       OPT_BOOL(0, "tags", &tags_only, N_("only show tags (can be combined with heads)")),
+       OPT_BOOL(0, "heads", &heads_only, N_("only show heads (can be combined with tags)")),
+       OPT_BOOL(0, "verify", &verify, N_("stricter reference checking, "
                    "requires exact ref path")),
-       { OPTION_BOOLEAN, 'h', NULL, &show_head, NULL,
-         N_("show the HEAD reference, even if it would be filtered out"),
-         PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
-       OPT_BOOLEAN(0, "head", &show_head,
+       OPT_HIDDEN_BOOL('h', NULL, &show_head,
+                       N_("show the HEAD reference, even if it would be filtered out")),
+       OPT_BOOL(0, "head", &show_head,
          N_("show the HEAD reference, even if it would be filtered out")),
-       OPT_BOOLEAN('d', "dereference", &deref_tags,
+       OPT_BOOL('d', "dereference", &deref_tags,
                    N_("dereference tags into object IDs")),
        { OPTION_CALLBACK, 's', "hash", &abbrev, N_("n"),
          N_("only show SHA1 hash using <n> digits"),
@@ -209,12 +210,12 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
                if (!pattern)
                        die("--verify requires a reference");
                while (*pattern) {
-                       unsigned char sha1[20];
+                       struct object_id oid;
 
-                       if (!prefixcmp(*pattern, "refs/") &&
-                           !read_ref(*pattern, sha1)) {
+                       if (starts_with(*pattern, "refs/") &&
+                           !read_ref(*pattern, oid.hash)) {
                                if (!quiet)
-                                       show_one(*pattern, sha1);
+                                       show_one(*pattern, &oid);
                        }
                        else if (!quiet)
                                die("'%s' - not a valid ref", *pattern);