show-ref: allow glob-style ref matching
PATCH 1/1 show-ref: allow glob-style ref matching
show-ref without --verify will try to match pattern with fnmatch against the full refname and every suffix starting at a / in refname
---
I've been using ls .git/refs/tags/v1.4.* and other glob patterns to take a look at refs. This allows to use such patterns with show-ref. If this patch is accepted I'll add the missing documentation.
--- builtin-show-ref.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-)
builtin-show-ref.c +10 -11
@@ -34,21 +34,20 @@ static int show_ref(const char *refname, const unsigned char *sha1, int flag, voreturn 0 ; }if (pattern) { -int reflen =strlen (refname);const char **p = pattern, *m;while ((m = *p++) !=NULL ) { -int len =strlen (m); -if (len > reflen) -continue ; -if (memcmp (m, refname + reflen - len, len)) -continue ; -if (len == reflen) - goto match; +const char *r = refname;/* "--verify" requires an exact match */ -if (verify) +if (verify) { +if (strcmp (m, refname)) + goto match;continue ; -if (refname[reflen - len -1 ] =='/' ) - goto match; + } +do { +if (!fnmatch (m, r,0 )) + goto match; + r =index (r,'/' ); + }while (r++); }return 0 ; }
Signature · 1 line
1.5.0.rc2.g18af