Skip to content

Commit 2246937

Browse files
committed
Merge branch 'tb/show-ref-optim'
"git show-ref --heads" (and "--tags") still iterated over all the refs only to discard refs outside the specified area, which has been corrected. * tb/show-ref-optim: builtin/show-ref.c: avoid over-iterating with --heads, --tags
2 parents 11698e5 + c0c9d35 commit 2246937

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

builtin/show-ref.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ static int show_ref(const char *refname, const struct object_id *oid,
5252
if (show_head && !strcmp(refname, "HEAD"))
5353
goto match;
5454

55-
if (tags_only || heads_only) {
56-
int match;
57-
58-
match = heads_only && starts_with(refname, "refs/heads/");
59-
match |= tags_only && starts_with(refname, "refs/tags/");
60-
if (!match)
61-
return 0;
62-
}
6355
if (pattern) {
6456
int reflen = strlen(refname);
6557
const char **p = pattern, *m;
@@ -216,7 +208,14 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
216208

217209
if (show_head)
218210
head_ref(show_ref, NULL);
219-
for_each_ref(show_ref, NULL);
211+
if (heads_only || tags_only) {
212+
if (heads_only)
213+
for_each_fullref_in("refs/heads/", show_ref, NULL);
214+
if (tags_only)
215+
for_each_fullref_in("refs/tags/", show_ref, NULL);
216+
} else {
217+
for_each_ref(show_ref, NULL);
218+
}
220219
if (!found_match) {
221220
if (verify && !quiet)
222221
die("No match");

0 commit comments

Comments
 (0)