Re: [PATCH v3 5/9] ref-filter: add option to match literal pattern

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

 



On Sat, Jul 18, 2015 at 3:12 PM, Karthik Nayak <karthik.188@xxxxxxxxx> wrote:
> 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 85c561e..7ff3ded 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -966,6 +980,15 @@ static int match_name_as_path(const char **pattern, const char *refname)
>         return 0;
>  }
>
> +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);
> +}
> +
>  /*
>   * Given a ref (sha1, refname), check if the ref belongs to the array
>   * of sha1s. If the given ref is a tag, check if the given tag points
> @@ -1034,7 +1057,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
>                 return 0;
>         }
>
> -       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...

>         if (filter->points_at.nr && !match_points_at(&filter->points_at, oid->hash, refname))
--
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]