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

Re: [PATCH v3 1/2] sequencer: factor out parsing of todo commands

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jun 23, 2026, 15:53 UTC
Message-ID
<65d38915-019e-4e2c-838f-980023e0c2af@gmail.com>
In-Reply-To
<xmqqpl1i1pef.fsf@gitster.g>
On 22/06/2026 18:00, Junio C Hamano wrote:
Show 14 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> Move the code that parses todo commands into a separate function so
>> that it can be shared with "git status" in the next commit. As we
>> know the input is NUL terminated we do not pass a pointer to the end
>> of the line and instead test for a blank line by looking for NUL, CR
>> LF, or LF. We use starts_with() instead of starts_with_mem() for the
>> same reason. This results in slightly different behavior when there
>> a CR at the start of the line that is not followed by LF. Previously
>> such a line was treated as a comment rather than an invalid line.
> 
> Meaning that the input validation is tighter than before? 
Yes
> I think
> it is fine in this case, as I do not see a reason why anybody wants
> to use a lone CR as comment introducer.

Agreed. In the unlikely event that core.commentChar starts with a CR we still treat the line as a comment, but we don't treat lines starting with a CR as a comment anymore. I think that behavior was a lazy way of handling empty lines with CR LF line endings.

Thanks
Phillip
Show 70 quoted lines
>> +bool sequencer_parse_todo_command(const char **p, enum todo_command *cmd)
>> +{
>> +	const char *s = *p;
>> +
>> +	for (int i = 0; i < TODO_COMMENT; i++)
>> +		if (is_command(i, p)) {
>> +			*cmd = i;
>> +			return true;
>> +		}
>> +
>> +	if (starts_with(s, comment_line_str)) {
>> +		*cmd = TODO_COMMENT;
>> +		return true;
>> +	} else if (s[0] == '\n' || (s[0] == '\r' && s[1] == '\n') || !s[0]) {
>> +		*cmd = TODO_COMMENT;
>> +		return true;
>> +	}
>> +
>> +	return false;
>>   }
> 
> I notice that the order of noticing concrete comments and comment
> lines are swapped relative to the original.  There is no inherently
> "natural" order between them, so the change is perfectly OK.  I just
> got confused slightly while reading it until I realized that is what
> you did.
> 
>>   static int check_label_or_ref_arg(enum todo_command command, const char *arg)
>> @@ -2716,29 +2737,23 @@ static int parse_insn_line(struct repository *r, struct replay_opts *opts,
>>   {
>>   	struct object_id commit_oid;
>>   	char *end_of_object_name;
>> -	int i, saved, status, padding;
>> +	int saved, status, padding;
>>   
>>   	item->flags = 0;
>>   
>>   	/* left-trim */
>>   	bol += strspn(bol, " \t");
>>   
>> -	if (bol == eol || *bol == '\r' || starts_with_mem(bol, eol - bol, comment_line_str)) {
>> -		item->command = TODO_COMMENT;
>> -		item->commit = NULL;
>> -		item->arg_offset = bol - buf;
>> -		item->arg_len = eol - bol;
>> -		return 0;
>> -	}
>> -
>> -	for (i = 0; i < TODO_COMMENT; i++)
>> -		if (is_command(i, &bol)) {
>> -			item->command = i;
>> -			break;
>> -		}
>> -	if (i >= TODO_COMMENT)
>> +	if (!sequencer_parse_todo_command(&bol, &item->command))
>>   		return error(_("invalid command '%.*s'"),
>>   			     (int)strcspn(bol, " \t\r\n"), bol);
>> +
>> +	if (item->command == TODO_COMMENT) {
>> +		item->commit = NULL;
>> +		item->arg_offset = bol - buf;
>> +		item->arg_len = eol - bol;
>> +		return 0;
>> +	}
> 
> And the extra stuff that are only relevant to a comment line is
> naturally processed by the caller.  OK.
> 
> Thanks.  Looking good so far.
> 
Previous: Junio C HamanoNext: Phillip Wood
Message 22 of 29 in “status: improve rebase todo list parsing”
  1. 0/2 status: improve rebase todo list parsingPhillip Wood, Apr 20, 2026
  2. 1/2 sequencer: factor out parsing of todo commandsPhillip Wood, Apr 20, 2026
  3. Elijah NewrenApr 22, 2026
  4. 2/2 status: improve rebase todo list parsingPhillip Wood, Apr 20, 2026
  5. Tian YuchenApr 20, 2026
  6. Phillip WoodApr 21, 2026
  7. Elijah NewrenApr 22, 2026
  8. Patrick SteinhardtApr 22, 2026
  9. Phillip WoodApr 22, 2026
  10. Phillip WoodApr 22, 2026
  11. 0/2 status: improve rebase todo list parsingPhillip Wood, May 1, 2026
  12. 1/2 sequencer: factor out parsing of todo commandsPhillip Wood, May 1, 2026
  13. 2/2 status: improve rebase todo list parsingPhillip Wood, May 1, 2026
  14. Junio C HamanoMay 31, 2026
  15. Phillip WoodJun 1, 2026
  16. Junio C HamanoJun 11, 2026
  17. Phillip WoodJun 22, 2026
  18. Phillip WoodMay 1, 2026
  19. 0/2 status: improve rebase todo list parsingPhillip Wood, Jun 22, 2026
  20. 1/2 sequencer: factor out parsing of todo commandsPhillip Wood, Jun 22, 2026
  21. Junio C HamanoJun 22, 2026
  22. Phillip WoodJun 23, 2026
  23. 2/2 status: improve rebase todo list parsingPhillip Wood, Jun 22, 2026
  24. Junio C HamanoJun 22, 2026
  25. Junio C HamanoJun 22, 2026
  26. Phillip WoodJun 23, 2026
  27. 0/2 status: improve rebase todo list parsingPhillip Wood, Jun 23, 2026
  28. 1/2 sequencer: factor out parsing of todo commandsPhillip Wood, Jun 23, 2026
  29. 2/2 status: improve rebase todo list parsingPhillip Wood, Jun 23, 2026

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.