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

Re: [PATCH] fmt-merge-msg: use skip_prefix() instead of starts_with()

From
Jeff King <peff@peff.net>
Date
Nov 26, 2019, 16:10 UTC
Message-ID
<20191126161053.GE25729@sigill.intra.peff.net>
In-Reply-To
<8fa33928-3cbc-beba-524b-55bca143fd80@web.de>
On Tue, Nov 26, 2019 at 03:22:56PM +0100, René Scharfe wrote:
Show 29 quoted lines
> diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
> index a4615587fd..736f666f64 100644
> --- a/builtin/fmt-merge-msg.c
> +++ b/builtin/fmt-merge-msg.c
> @@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
>  	int i, len = strlen(line);
>  	struct origin_data *origin_data;
>  	char *src;
> -	const char *origin;
> +	const char *origin, *tag_name;
>  	struct src_data *src_data;
>  	struct string_list_item *item;
>  	int pulling_head = 0;
> @@ -162,14 +162,13 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
>  	if (pulling_head) {
>  		origin = src;
>  		src_data->head_status |= 1;
> -	} else if (starts_with(line, "branch ")) {
> +	} else if (skip_prefix(line, "branch ", &origin)) {
>  		origin_data->is_local_branch = 1;
> -		origin = line + 7;
>  		string_list_append(&src_data->branch, origin);
>  		src_data->head_status |= 2;
> -	} else if (starts_with(line, "tag ")) {
> +	} else if (skip_prefix(line, "tag ", &tag_name)) {
>  		origin = line;
> -		string_list_append(&src_data->tag, origin + 4);
> +		string_list_append(&src_data->tag, tag_name);
>  		src_data->head_status |= 2;

Looks good, as we're already mutating "origin" in the first one, and "tag_name" is a new variable in the second one.

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