diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-06-13 15:53:42 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-06-13 15:53:42 -0700 |
| commit | 2246937e4165d4a7a238f1ea52da36bc7aa1274a (patch) | |
| tree | fe82609bfa03d22f8d125539cc1e30fa02f79f1a /builtin | |
| parent | 11698e551ce0590af6d7ce1f5b683eca27e68ab3 (diff) | |
| parent | c0c9d35e27e777d117362f6e96f433eb2b55bf76 (diff) | |
| download | git-2246937e4165d4a7a238f1ea52da36bc7aa1274a.tar.gz | |
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
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/show-ref.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 7f8a5332f8..5fa207a044 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -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; @@ -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"); |
