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

Re: [PATCH] fetch: use skip_prefix() instead of starts_with()

From
Jeff King <peff@peff.net>
Date
Nov 26, 2019, 16:09 UTC
Message-ID
<20191126160934.GD25729@sigill.intra.peff.net>
In-Reply-To
<f6ed729b-3cd3-a91a-d69d-4960e4a0524f@web.de>
On Tue, Nov 26, 2019 at 12:18:26PM +0100, René Scharfe wrote:
Show 24 quoted lines
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 863c858fde..02e8619618 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -954,18 +954,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
>  				kind = "";
>  				what = "";
>  			}
> -			else if (starts_with(rm->name, "refs/heads/")) {
> +			else if (skip_prefix(rm->name, "refs/heads/", &what))
>  				kind = "branch";
> -				what = rm->name + 11;
> -			}
> -			else if (starts_with(rm->name, "refs/tags/")) {
> +			else if (skip_prefix(rm->name, "refs/tags/", &what))
>  				kind = "tag";
> -				what = rm->name + 10;
> -			}
> -			else if (starts_with(rm->name, "refs/remotes/")) {
> +			else if (skip_prefix(rm->name, "refs/remotes/", &what))
>  				kind = "remote-tracking branch";
> -				what = rm->name + 13;
> -			}
>  			else {

Yep, this one looks obviously correct. We were already mutating "what", so this just does it inside skip_prefix(). Much nicer.

-Peff
Previous: René Scharfe
Message 2 of 2 in “fetch: use skip_prefix() instead of starts_with()”
  1. fetch: use skip_prefix() instead of starts_with()René Scharfe, Nov 26, 2019
  2. Jeff KingNov 26, 2019

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.