{"thread":{"id":"6542","subject":"[PATCH] show-ref: allow glob-style ref matching","startedAt":"2007-01-26T09:50:26Z","lastAt":"2007-01-26T09:50:26Z","messageCount":1,"participants":["Matthias Lederhofer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32709","messageId":"20070126095026.GA31802@moooo.ath.cx","threadId":"6542","inReplyTo":null,"subject":"[PATCH] show-ref: allow glob-style ref matching","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2007-01-26T09:50:26Z","receivedAt":"2007-01-26T09:50:26Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"show-ref without --verify will try to match pattern with\nfnmatch against the full refname and every suffix starting\nat a / in refname\n---\nI've been using ls .git/refs/tags/v1.4.* and other glob patterns to\ntake a look at refs.  This allows to use such patterns with show-ref.\nIf this patch is accepted I'll add the missing documentation.\n---\n builtin-show-ref.c |   21 ++++++++++-----------\n 1 files changed, 10 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin-show-ref.c b/builtin-show-ref.c\nindex 853f13f..64a1246 100644\n--- a/builtin-show-ref.c\n+++ b/builtin-show-ref.c\n@@ -34,21 +34,20 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \t\t\treturn 0;\n \t}\n \tif (pattern) {\n-\t\tint reflen = strlen(refname);\n \t\tconst char **p = pattern, *m;\n \t\twhile ((m = *p++) != NULL) {\n-\t\t\tint len = strlen(m);\n-\t\t\tif (len > reflen)\n-\t\t\t\tcontinue;\n-\t\t\tif (memcmp(m, refname + reflen - len, len))\n-\t\t\t\tcontinue;\n-\t\t\tif (len == reflen)\n-\t\t\t\tgoto match;\n+\t\t\tconst char *r = refname;\n \t\t\t/* \"--verify\" requires an exact match */\n-\t\t\tif (verify)\n+\t\t\tif (verify) {\n+\t\t\t\tif (strcmp(m, refname))\n+\t\t\t\t\tgoto match;\n \t\t\t\tcontinue;\n-\t\t\tif (refname[reflen - len - 1] == '/')\n-\t\t\t\tgoto match;\n+\t\t\t}\n+\t\t\tdo {\n+\t\t\t\tif (!fnmatch(m, r, 0))\n+\t\t\t\t\tgoto match;\n+\t\t\t\tr = index(r, '/');\n+\t\t\t} while (r++);\n \t\t}\n \t\treturn 0;\n \t}\n-- \n1.5.0.rc2.g18af\n"}]}