On Mon, Jul 20, 2015 at 4:01 AM, Christian Couder
<christian.cou...@gmail.com> wrote:
> On Mon, Jul 20, 2015 at 8:24 AM, Eric Sunshine <sunsh...@sunshineco.com> 
> wrote:
>> On Sat, Jul 18, 2015 at 3:12 PM, Karthik Nayak <karthik....@gmail.com> wrote:
>>> +static int filter_pattern_match(struct ref_filter *filter, const char 
>>> *refname)
>>> +{
>>> +       if (!*filter->name_patterns)
>>> +               return 1;
>>> +       if (filter->match_as_path)
>>> +               return match_name_as_path(filter->name_patterns, refname);
>>> +       return match_pattern(filter->name_patterns, refname);
>>> +}
>>> @@ -1034,7 +1057,7 @@ static int ref_filter_handler(const char *refname, 
>>> const struct object_id *oid,
>>> -       if (*filter->name_patterns && 
>>> !match_name_as_path(filter->name_patterns, refname))
>>> +       if (!filter_pattern_match(filter, refname))
>>>                 return 0;
>>
>> I find it much more difficult to grok the new logic due to
>> '*filter->name_patterns' having moved into the called function and its
>> negation inside the function returning 1 which is then negated (again)
>> upon return here. This sort of twisty logic places a higher cognitive
>> load on the reader. Retaining the original logic makes the code far
>> simpler to understand:
>>
>>     if (*filter->name_patterns &&
>>         !filter_pattern_match(filter, refname))
>>         return 0;
>>
>> although it's a bit less nicely encapsulated, so I dunno...
>
> I think a comment before filter_pattern_match() and perhaps also one
> inside it might help. For example something like:
>
> /* Return 1 if the refname matches one of the patterns, otherwise 0. */
> static int filter_pattern_match(struct ref_filter *filter, const char 
> *refname)
> {
>        if (!*filter->name_patterns)
>                return 1; /* No pattern always matches */
>        if (filter->match_as_path)
>                return match_name_as_path(filter->name_patterns, refname);
>        return match_pattern(filter->name_patterns, refname);
> }

Yes, the comments do improve the situation and may be a reasonable compromise...
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to