Jeff King <p...@peff.net> writes:

> Subject: Re: [PATCH 1/2] ref-filter: split ref_kind_from_filter

I think you meant ref_kind_from_refname() ;-)

Looks like a good idea.

> This function does two things: if we know we are filtering
> only a certain kind of ref, then we can immediately know
> that we have that kind. If not, then we compute the kind
> from the fully-qualified refname. The latter half is useful
> for other callers; let's split it out.
>
> Signed-off-by: Jeff King <p...@peff.net>
> ---
>  ref-filter.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index cfbcd73..77ec9de 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -1329,7 +1329,7 @@ static struct ref_array_item *new_ref_array_item(const 
> char *refname,
>       return ref;
>  }
>  
> -static int filter_ref_kind(struct ref_filter *filter, const char *refname)
> +static int ref_kind_from_refname(const char *refname)
>  {
>       unsigned int i;
>  
> @@ -1342,11 +1342,7 @@ static int filter_ref_kind(struct ref_filter *filter, 
> const char *refname)
>               { "refs/tags/", FILTER_REFS_TAGS}
>       };
>  
> -     if (filter->kind == FILTER_REFS_BRANCHES ||
> -         filter->kind == FILTER_REFS_REMOTES ||
> -         filter->kind == FILTER_REFS_TAGS)
> -             return filter->kind;
> -     else if (!strcmp(refname, "HEAD"))
> +     if (!strcmp(refname, "HEAD"))
>               return FILTER_REFS_DETACHED_HEAD;
>  
>       for (i = 0; i < ARRAY_SIZE(ref_kind); i++) {
> @@ -1357,6 +1353,15 @@ static int filter_ref_kind(struct ref_filter *filter, 
> const char *refname)
>       return FILTER_REFS_OTHERS;
>  }
>  
> +static int filter_ref_kind(struct ref_filter *filter, const char *refname)
> +{
> +     if (filter->kind == FILTER_REFS_BRANCHES ||
> +         filter->kind == FILTER_REFS_REMOTES ||
> +         filter->kind == FILTER_REFS_TAGS)
> +             return filter->kind;
> +     return ref_kind_from_refname(refname);
> +}
> +
>  /*
>   * A call-back given to for_each_ref().  Filter refs and keep them for
>   * later object processing.

Reply via email to