lock_ref_sha1(): do not sometimes error() and sometimes die().
[gitweb.git] / builtin-show-ref.c
index 161b2367ead7c15876902dc5c297e30b82063fd6..12c457c3c1acb888d4b3442d11db0f8b414c2d82 100644 (file)
@@ -3,12 +3,13 @@
 #include "object.h"
 #include "tag.h"
 
-static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [--tags] [--heads] [--] [pattern*]";
+static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash] [--tags] [--heads] [--] [pattern*]";
 
-static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, found_match = 0, verify = 0, quiet = 0;
+static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0,
+       found_match = 0, verify = 0, quiet = 0, hash_only = 0;
 static const char **pattern;
 
-static int show_ref(const char *refname, const unsigned char *sha1)
+static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
 {
        struct object *obj;
 
@@ -50,7 +51,10 @@ static int show_ref(const char *refname, const unsigned char *sha1)
        }
        if (quiet)
                return 0;
-       printf("%s %s\n", sha1_to_hex(sha1), refname);
+       if (hash_only)
+               printf("%s\n", sha1_to_hex(sha1));
+       else
+               printf("%s %s\n", sha1_to_hex(sha1), refname);
        if (deref_tags && obj->type == OBJ_TAG) {
                obj = deref_tag(obj, refname, 0);
                printf("%s %s^{}\n", sha1_to_hex(obj->sha1), refname);
@@ -86,6 +90,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
                        deref_tags = 1;
                        continue;
                }
+               if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) {
+                       hash_only = 1;
+                       continue;
+               }
                if (!strcmp(arg, "--verify")) {
                        verify = 1;
                        continue;
@@ -101,8 +109,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
                usage(show_ref_usage);
        }
        if (show_head)
-               head_ref(show_ref);
-       for_each_ref(show_ref);
+               head_ref(show_ref, NULL);
+       for_each_ref(show_ref, NULL);
        if (!found_match) {
                if (verify && !quiet)
                        die("No match");