6 static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [-s|--hash] [--tags] [--heads] [--] [pattern*]";
8 static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0,
9 found_match = 0, verify = 0, quiet = 0, hash_only = 0;
10 static const char **pattern;
12 static int show_ref(const char *refname, const unsigned char *sha1)
16 if (tags_only || heads_only) {
19 match = heads_only && !strncmp(refname, "refs/heads/", 11);
20 match |= tags_only && !strncmp(refname, "refs/tags/", 10);
25 int reflen = strlen(refname);
26 const char **p = pattern, *m;
27 while ((m = *p++) != NULL) {
31 if (memcmp(m, refname + reflen - len, len))
35 /* "--verify" requires an exact match */
38 if (refname[reflen - len - 1] == '/')
46 obj = parse_object(sha1);
50 die("git-show-ref: bad ref %s (%s)", refname, sha1_to_hex(sha1));
55 printf("%s\n", sha1_to_hex(sha1));
57 printf("%s %s\n", sha1_to_hex(sha1), refname);
58 if (deref_tags && obj->type == OBJ_TAG) {
59 obj = deref_tag(obj, refname, 0);
60 printf("%s %s^{}\n", sha1_to_hex(obj->sha1), refname);
65 int cmd_show_ref(int argc, const char **argv, const char *prefix)
69 for (i = 1; i < argc; i++) {
70 const char *arg = argv[i];
75 if (!strcmp(arg, "--")) {
76 pattern = argv + i + 1;
81 if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) {
85 if (!strcmp(arg, "-h") || !strcmp(arg, "--head")) {
89 if (!strcmp(arg, "-d") || !strcmp(arg, "--dereference")) {
93 if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) {
97 if (!strcmp(arg, "--verify")) {
101 if (!strcmp(arg, "--tags")) {
105 if (!strcmp(arg, "--heads")) {
109 usage(show_ref_usage);
113 for_each_ref(show_ref);
115 if (verify && !quiet)