Re: [PATCH v5 07/11] ref-filter: add option to match literal pattern
flat view
From: Karthik Nayak <hidden>
Date: 2016-06-15 23:05:57
On Wed, Jul 29, 2015 at 3:19 AM, Eric Sunshine [off-list ref] wrote:
On Mon, Jul 27, 2015 at 3:27 AM, Karthik Nayak [off-list ref] wrote:quoted
From: Karthik Nayak <redacted> 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 <redacted> ---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);
Gives a "warning: value computed is not used [-Wunused-value]"
so I typecasted the output as:
(void)(skip_prefix(refname, "refs/tags/", &refname) ||
skip_prefix(refname, "refs/heads/", &refname) ||
skip_prefix(refname, "refs/remotes/", &refname));
Just wondering if that's alright.
--
Regards,
Karthik Nayak