6 static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=<length>]] [--abbrev[=<length>]] [--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, abbrev = 0;
10 static const char **pattern;
12 static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)
17 if (tags_only || heads_only) {
20 match = heads_only && !strncmp(refname, "refs/heads/", 11);
21 match |= tags_only && !strncmp(refname, "refs/tags/", 10);
26 int reflen = strlen(refname);
27 const char **p = pattern, *m;
28 while ((m = *p++) != NULL) {
32 if (memcmp(m, refname + reflen - len, len))
36 /* "--verify" requires an exact match */
39 if (refname[reflen - len - 1] == '/')
47 obj = parse_object(sha1);
51 die("git-show-ref: bad ref %s (%s)", refname, sha1_to_hex(sha1));
56 hex = find_unique_abbrev(sha1, abbrev);
60 printf("%s %s\n", hex, refname);
61 if (deref_tags && obj->type == OBJ_TAG) {
62 obj = deref_tag(obj, refname, 0);
63 hex = find_unique_abbrev(obj->sha1, abbrev);
64 printf("%s %s^{}\n", hex, refname);
69 int cmd_show_ref(int argc, const char **argv, const char *prefix)
73 for (i = 1; i < argc; i++) {
74 const char *arg = argv[i];
79 if (!strcmp(arg, "--")) {
80 pattern = argv + i + 1;
85 if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) {
89 if (!strcmp(arg, "-h") || !strcmp(arg, "--head")) {
93 if (!strcmp(arg, "-d") || !strcmp(arg, "--dereference")) {
97 if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) {
101 if (!strncmp(arg, "--hash=", 7) ||
102 (!strncmp(arg, "--abbrev", 8) &&
103 (arg[8] == '=' || arg[8] == '\0'))) {
104 if (arg[3] != 'h' && !arg[8])
106 abbrev = DEFAULT_ABBREV;
108 /* --hash= or --abbrev= */
116 abbrev = strtoul(arg, &end, 10);
117 if (*end || abbrev > 40)
118 usage(show_ref_usage);
119 if (abbrev < MINIMUM_ABBREV)
120 abbrev = MINIMUM_ABBREV;
124 if (!strcmp(arg, "--verify")) {
128 if (!strcmp(arg, "--tags")) {
132 if (!strcmp(arg, "--heads")) {
136 usage(show_ref_usage);
139 head_ref(show_ref, NULL);
140 for_each_ref(show_ref, NULL);
142 if (verify && !quiet)