aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/show-ref.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/show-ref.c')
-rw-r--r--builtin/show-ref.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 7f8a5332f8..3af6a53ee9 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -9,7 +9,9 @@
#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 [-q | --quiet] [--verify] [--head] [-d | --dereference]\n"
+ " [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags]\n"
+ " [--heads] [--] [<pattern>...]"),
N_("git show-ref --exclude-existing[=<pattern>]"),
NULL
};
@@ -47,19 +49,11 @@ static void show_one(const char *refname, const struct object_id *oid)
}
static int show_ref(const char *refname, const struct object_id *oid,
- int flag, void *cbdata)
+ int flag UNUSED, void *cbdata UNUSED)
{
if (show_head && !strcmp(refname, "HEAD"))
goto match;
- if (tags_only || heads_only) {
- int match;
-
- match = heads_only && starts_with(refname, "refs/heads/");
- match |= tags_only && starts_with(refname, "refs/tags/");
- if (!match)
- return 0;
- }
if (pattern) {
int reflen = strlen(refname);
const char **p = pattern, *m;
@@ -85,8 +79,9 @@ match:
return 0;
}
-static int add_existing(const char *refname, const struct object_id *oid,
- int flag, void *cbdata)
+static int add_existing(const char *refname,
+ const struct object_id *oid UNUSED,
+ int flag UNUSED, void *cbdata)
{
struct string_list *list = (struct string_list *)cbdata;
string_list_insert(list, refname);
@@ -216,7 +211,14 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
if (show_head)
head_ref(show_ref, NULL);
- for_each_ref(show_ref, NULL);
+ if (heads_only || tags_only) {
+ if (heads_only)
+ for_each_fullref_in("refs/heads/", show_ref, NULL);
+ if (tags_only)
+ for_each_fullref_in("refs/tags/", show_ref, NULL);
+ } else {
+ for_each_ref(show_ref, NULL);
+ }
if (!found_match) {
if (verify && !quiet)
die("No match");