Skip to content

Commit

Permalink
Merge branch 'tb/show-ref-optim' into jch
Browse files Browse the repository at this point in the history
"git show-ref --heads" (and "--tags") still iterated over all the
refs, which has been corrected.

* tb/show-ref-optim:
  builtin/show-ref.c: avoid over-iterating with --heads, --tags
  • Loading branch information
gitster committed Jun 13, 2022
2 parents c1212d7 + c0c9d35 commit cf9edd2
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions builtin/show-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ static int show_ref(const char *refname, const struct object_id *oid,
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;
Expand Down Expand Up @@ -216,7 +208,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");
Expand Down

0 comments on commit cf9edd2

Please sign in to comment.