Re: [PATCH v5 07/11] ref-filter: add option to match literal pattern

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);
>

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
--
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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]