On Wed, Jul 29, 2015 at 3:19 AM, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote: > On Mon, Jul 27, 2015 at 3:27 AM, Karthik Nayak <karthik.188@xxxxxxxxx> wrote: >> From: Karthik Nayak <karthik.188@xxxxxxxxx> >> >> Since 'ref-filter' only has an option to match path names add an >> option for plain fnmatch pattern-matching. >> >> This is to support the pattern matching options which are used in `git >> tag -l` and `git branch -l` where we can match patterns like `git tag >> -l foo*` which would match all tags which has a "foo*" pattern. >> >> Signed-off-by: Karthik Nayak <karthik.188@xxxxxxxxx> >> --- >> diff --git a/ref-filter.c b/ref-filter.c >> index 26eb26c..597b189 100644 >> --- a/ref-filter.c >> +++ b/ref-filter.c >> @@ -946,6 +946,32 @@ static int commit_contains(struct ref_filter *filter, struct commit *commit) >> >> /* >> * Return 1 if the refname matches one of the patterns, otherwise 0. >> + * A pattern can be a literal prefix (e.g. a refname "refs/heads/master" >> + * matches a pattern "refs/heads/mas") or a wildcard (e.g. the same ref >> + * matches "refs/heads/mas*", too). >> + */ >> +static int match_pattern(const char **patterns, const char *refname) >> +{ >> + /* >> + * When no '--format' option is given we need to skip the prefix >> + * for matching refs of tags and branches. >> + */ >> + if (skip_prefix(refname, "refs/tags/", &refname)) >> + ; >> + else if (skip_prefix(refname, "refs/heads/", &refname)) >> + ; >> + else if (skip_prefix(refname, "refs/remotes/", &refname)) >> + ; > > Or, more concisely: > > skip_prefix(refname, "refs/tags/", &refname) || > skip_prefix(refname, "refs/heads/", &refname) || > skip_prefix(refname, "refs/remotes/", &refname); > > since || short-circuits. No need for the 'if' or cascading 'else if's. > >> + for (; *patterns; patterns++) { >> + if (!wildmatch(*patterns, refname, 0, NULL)) >> + return 1; >> + } >> + return 0; >> +} Looks better thanks :) -- Regards, Karthik Nayak -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html