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

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

From
Jeff King <peff@peff.net>
Date
Nov 26, 2019, 15:57 UTC
Message-ID
<20191126155741.GB25729@sigill.intra.peff.net>
In-Reply-To
<90f94e4b-6cf3-58cc-01dc-c3d731037217@web.de>
On Tue, Nov 26, 2019 at 04:18:28PM +0100, René Scharfe wrote:
Show 20 quoted lines
> diff --git a/builtin/push.c b/builtin/push.c
> index 843f5b22a2..6dbf0f0bb7 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;
>  static const char *map_refspec(const char *ref,
>  			       struct remote *remote, struct ref *local_refs)
>  {
> +	const char *branch_name;
>  	struct ref *matched = NULL;
> 
>  	/* Does "ref" uniquely name our ref? */
> @@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,
>  	}
> 
>  	if (push_default == PUSH_DEFAULT_UPSTREAM &&
> -	    starts_with(matched->name, "refs/heads/")) {
> -		struct branch *branch = branch_get(matched->name + 11);
> +	    skip_prefix(matched->name, "refs/heads/", &branch_name)) {
> +		struct branch *branch = branch_get(branch_name);

Yep, obviously correct because you introduce a new variable instead of mutating an existing one. Looks good.

-Peff
Previous: René Scharfe
Message 2 of 2 in “push: use skip_prefix() instead of starts_with()”
  1. push: 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.