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

Re: [PATCH 1/2] rebase -i: match whole word in is_command()

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 23, 2023, 22:25 UTC
Message-ID
<xmqq5ybs6mv0.fsf@gitster.g>
In-Reply-To
<b050e7c1a4daf6c65aa9b2b6f44248d7b403918e.1677185702.git.gitgitgadget@gmail.com>
"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 12 quoted lines
>  	const char *str = todo_command_info[command].str;
>  	const char nick = todo_command_info[command].c;
> -	const char *p = *bol + 1;
> +	const char *p = *bol;
>  
> -	return skip_prefix(*bol, str, bol) ||
> -		((nick && **bol == nick) &&
> -		 (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) &&
> -		 (*bol = p));
> +	return (skip_prefix(p, str, &p) || (nick && *p++ == nick)) &&
> +		(*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || !*p) &&
> +		(*bol = p);

OK. So we skip the command name string in the line given by the end-user (or see if the first letter matches the single letter command) and make sure it is followed by a whitespace or EOL in either case. The old code was not doing the "end of word" check for the longhand at all, which was clearly wrong.

I too find "&& (*bol = p)" that pretends to be a Boolean condition but is there only for its side effect distasteful, but I agree with you that fixing it is outside the scope of this patch.

Show 7 quoted lines
> @@ -2513,7 +2512,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
>  			break;
>  		}
>  	if (i >= TODO_COMMENT)
> -		return -1;
> +		return error(_("invalid command '%.*s'"),
> +			     (int)strcspn(bol, " \t\r\n"), bol);
Nice.
Show 10 quoted lines
> diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
> index b57541356bd..1d2f0429aea 100644
> --- a/t/lib-rebase.sh
> +++ b/t/lib-rebase.sh
> @@ -60,7 +60,7 @@ set_fake_editor () {
>  		">")
>  			echo >> "$1";;
>  		bad)
> -			action="badcmd";;
> +			action="pickled";;
;-)
Previous: Phillip Wood via GitGitGadgetNext: Jeff King
Message 3 of 8 in “sequencer parsing fixes”
  1. 0/2 sequencer parsing fixesPhillip Wood via GitGitGadget, Feb 23, 2023
  2. 1/2 rebase -i: match whole word in is_command()Phillip Wood via GitGitGadget, Feb 23, 2023
  3. Junio C HamanoFeb 23, 2023
  4. Jeff KingFeb 26, 2023
  5. 2/2 rebase -i: fix parsing of "fixup -C<commit>"Phillip Wood via GitGitGadget, Feb 23, 2023
  6. Junio C HamanoFeb 23, 2023
  7. Johannes SchindelinFeb 24, 2023
  8. Junio C HamanoFeb 24, 2023

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.