git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 19, 2016, 21:23 UTC
Message-ID
<xmqqd1iwkp7m.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161019203546.dfqmi2czcxopgj6w@sigill.intra.peff.net>
Jeff King <peff@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.
Show 53 quoted lines
> 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 <peff@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.
Previous: Jeff KingNext: Jeff King
Message 3 of 7 in “Re: [PATCH v4 2/7] ref-filter: add function to print single ref_array_item”
  1. Jeff KingOct 19, 2016
  2. 1/2 ref-filter: split ref_kind_from_filterJeff King, Oct 19, 2016
  3. Junio C HamanoOct 19, 2016
  4. Jeff KingOct 19, 2016
  5. 2/2 tag: send fully qualified refnames to verify_tag_and_formatJeff King, Oct 19, 2016
  6. Santiago TorresOct 20, 2016
  7. Jeff KingOct 20, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.