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

Re: [PATCH v2] refs: use skip_prefix() in ref_is_hidden()

From
Jeff King <peff@peff.net>
Date
Jul 24, 2017, 16:09 UTC
Message-ID
<20170724160938.bpdqf64p2ja2vvbd@sigill.intra.peff.net>
In-Reply-To
<20170722043912.32118-1-chriscool@tuxfamily.org>
On Sat, Jul 22, 2017 at 06:39:12AM +0200, Christian Couder wrote:
Show 12 quoted lines
> @@ -1175,10 +1175,9 @@ int ref_is_hidden(const char *refname, const char *refname_full)
>  		}
>  
>  		/* refname can be NULL when namespaces are used. */
> -		if (!subject || !starts_with(subject, match))
> -			continue;
> -		len = strlen(match);
> -		if (!subject[len] || subject[len] == '/')
> +		if (subject &&
> +		    skip_prefix(subject, match, &p) &&
> +		    (!*p || *p == '/'))
>  			return !neg;
This looks good to me.

I seem to recall running across a similar pattern elsewhere, where a caller wanted either an exact match, or a match ending with a particular character. We could add one more helper like:

  if (subject && skip_prefix_with_sep(subject, match, '/', &p))
	return !neg;

But I don't offhand recall where that other place was, and it's not like it's saving a huge amount of complexity in the caller. So I'll file it away in the back of my mind and see if it comes up a third time. ;)

-Peff
Previous: Christian Couder
Message 2 of 2 in “refs: use skip_prefix() in ref_is_hidden()”
  1. refs: use skip_prefix() in ref_is_hidden()Christian Couder, Jul 22, 2017
  2. Jeff KingJul 24, 2017

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.