6 static const char show_ref_usage
[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--deref] [--tags] [--heads] [--] [pattern*]";
8 static int deref_tags
= 0, show_head
= 0, tags_only
= 0, heads_only
= 0, found_match
= 0, verify
= 0, quiet
= 0;
9 static const char **pattern
;
11 static int show_ref(const char *refname
, const unsigned char *sha1
)
15 if (tags_only
|| heads_only
) {
18 match
= heads_only
&& !strncmp(refname
, "refs/heads/", 11);
19 match
|= tags_only
&& !strncmp(refname
, "refs/tags/", 10);
24 int reflen
= strlen(refname
);
25 const char **p
= pattern
, *m
;
26 while ((m
= *p
++) != NULL
) {
30 if (memcmp(m
, refname
+ reflen
- len
, len
))
34 /* "--verify" requires an exact match */
37 if (refname
[reflen
- len
- 1] == '/')
45 obj
= parse_object(sha1
);
49 die("git-show-ref: bad ref %s (%s)", refname
, sha1_to_hex(sha1
));
53 printf("%s %s\n", sha1_to_hex(sha1
), refname
);
54 if (deref_tags
&& obj
->type
== OBJ_TAG
) {
55 obj
= deref_tag(obj
, refname
, 0);
56 printf("%s %s^{}\n", sha1_to_hex(obj
->sha1
), refname
);
61 int cmd_show_ref(int argc
, const char **argv
, const char *prefix
)
65 for (i
= 1; i
< argc
; i
++) {
66 const char *arg
= argv
[i
];
71 if (!strcmp(arg
, "--")) {
72 pattern
= argv
+ i
+ 1;
77 if (!strcmp(arg
, "-q") || !strcmp(arg
, "--quiet")) {
81 if (!strcmp(arg
, "-h") || !strcmp(arg
, "--head")) {
85 if (!strcmp(arg
, "-d") || !strcmp(arg
, "--dereference")) {
89 if (!strcmp(arg
, "--verify")) {
93 if (!strcmp(arg
, "--tags")) {
97 if (!strcmp(arg
, "--heads")) {
101 usage(show_ref_usage
);
105 for_each_ref(show_ref
);
107 if (verify
&& !quiet
)