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

Re: [PATCH v2 2/2] rebase: fix todo-list rereading

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Sep 28, 2021, 10:20 UTC
Message-ID
<bed00cb7-2204-668c-dca5-4bc883e80bab@gmail.com>
In-Reply-To
<xmqqilyqvtmh.fsf@gitster.g>
On 24/09/2021 17:13, Junio C Hamano wrote:
Show 22 quoted lines
> "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> .... Instead of relying on stat
>> data this patch simply reads the possibly edited todo list and
>> compares it to the original with memcmp(). This is much faster than
>> reparsing the todo list each time.
> 
> Nice.  Is that an egg of Columbus or what ;-)
> 
>> +	if (strbuf_read_file_or_whine(&buf, get_todo_path(opts)) < 0)
>> +		return -1;
>> +	offset = get_item_line_offset(todo_list, todo_list->current + 1);
>> +	if (buf.len != todo_list->buf.len - offset ||
>> +	    memcmp(buf.buf, todo_list->buf.buf + offset, buf.len)) {
>>   		/* Reread the todo file if it has changed. */
>>   		todo_list_release(todo_list);
>>   		if (read_populate_todo(r, todo_list, opts))
> 
> As we already have the contents of hte file in the buffer, we could
> further refactor the code around read_populate_todo() to tell it not
> to reopen and reread the rebase-todo file (which risks toctou race),
> but that is OK for now, I would think.

I did wonder about doing that but decided to punt it for now, I don't think the race is a concern - if another process is writing to the todo list while rebase is picking commits it is asking for trouble already. I suspect doing this will be easier once git-rebase--preserve-merges.sh is gone from master.

Show 19 quoted lines
>> @@ -4271,6 +4267,7 @@ static int reread_todo_if_changed(struct repository *r,
>>   		/* `current` will be incremented on return */
>>   		todo_list->current = -1;
>>   	}
>> +	strbuf_release(&buf);
>>   
>>   	return 0;
>>   }
>> diff --git a/sequencer.h b/sequencer.h
>> index d57d8ea23d7..cdeb0c6be47 100644
>> --- a/sequencer.h
>> +++ b/sequencer.h
>> @@ -116,7 +116,6 @@ struct todo_list {
>>   	struct todo_item *items;
>>   	int nr, alloc, current;
>>   	int done_nr, total_nr;
>> -	struct stat_data stat;
> 
> Good riddance ;-)
Hear, hear!
> Will queue.  Thanks.
> 
Previous: Junio C HamanoNext: Phillip Wood via GitGitGadget
Message 29 of 31 in “rebase -i: a couple of small improvements”
  1. 0/5 rebase -i: a couple of small improvementsPhillip Wood via GitGitGadget, Sep 8, 2021
  2. 1/5 sequencer.c: factor out a functionPhillip Wood via GitGitGadget, Sep 8, 2021
  3. Eric SunshineSep 8, 2021
  4. Phillip WoodSep 9, 2021
  5. Johannes SchindelinSep 9, 2021
  6. 2/5 rebase: fix todo-list rereadingPhillip Wood via GitGitGadget, Sep 8, 2021
  7. Johannes SchindelinSep 9, 2021
  8. 3/5 reset_head(): mark oid parameter as constPhillip Wood via GitGitGadget, Sep 8, 2021
  9. 4/5 rebase -i: don't fork git checkoutPhillip Wood via GitGitGadget, Sep 8, 2021
  10. Philippe BlainSep 8, 2021
  11. Phillip WoodSep 9, 2021
  12. Philippe BlainSep 9, 2021
  13. Phillip WoodSep 9, 2021
  14. Elijah NewrenSep 9, 2021
  15. Philippe BlainSep 10, 2021
  16. Phillip WoodSep 15, 2021
  17. Johannes SchindelinSep 9, 2021
  18. Philippe BlainSep 9, 2021
  19. Johannes SchindelinSep 9, 2021
  20. Johannes SchindelinSep 10, 2021
  21. Philippe BlainSep 10, 2021
  22. Elijah NewrenSep 9, 2021
  23. 5/5 rebase: remove unused parameterPhillip Wood via GitGitGadget, Sep 8, 2021
  24. Johannes SchindelinSep 9, 2021
  25. Phillip WoodSep 9, 2021
  26. 0/2 rebase -i: a couple of small improvementsPhillip Wood via GitGitGadget, Sep 23, 2021
  27. 2/2 rebase: fix todo-list rereadingPhillip Wood via GitGitGadget, Sep 23, 2021
  28. Junio C HamanoSep 24, 2021
  29. Phillip WoodSep 28, 2021
  30. 1/2 sequencer.c: factor out a functionPhillip Wood via GitGitGadget, Sep 23, 2021
  31. Junio C HamanoSep 24, 2021

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.