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

Re: [PATCH] replay: support replaying down from root commit

From
Toon Claes <toon@iotcl.com>
Date
Mar 24, 2026, 17:25 UTC
Message-ID
<87qzp916o6.fsf@iotcl.com>
In-Reply-To
<xmqqwlzajkha.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 31 quoted lines
> Toon Claes <toon@iotcl.com> writes:
>
>> git-replay(1) doesn't allow replaying commits all the way down to the
>> root commit. Fix that.
>
> OK.
>
>> -	base = pickme->parents->item;
>> -	replayed_base = mapped_commit(replayed_commits, base, onto);
>> +	if (pickme->parents) {
>> +		base = pickme->parents->item;
>> +		replayed_base = mapped_commit(replayed_commits, base, onto);
>> +		base_tree = repo_get_commit_tree(repo, base);
>
> So, if we are replaying a commit with parent(s), we do the same as
> before (base_tree used to be computed a bit later).  But ...
>
>> +	} else {
>> +		base = NULL;
>> +		replayed_base = onto;
>> +		base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
>> +	}
>
> ... if we are replaying the root commit, there is no base (in
> contrast to "the first parent of the original commit" used in the
> other branch of this if-else construct).  We use an empty tree for
> the base_tree, which is the natural thing to use to replay for a
> root commit, of course.
>
> I am not sure why replayed_base is computed differently, though?  Is
> it because mapped_commit() would not work when base==NULL?
That's correct, mapped_commit() dereferences commit->object.oid.
> I have to wonder if the handling of that case should also be
> encapsulated inside mapped_commit() helper, just like the helper
> knows to "fallback" when the commit is not yet mapped
I'm fine either way, so I'll do that in v2.
> After all, if we drive that line of thought to the extreme, we would
> end up making repo_get_commit_tree() to return an empty tree object
> for base==NULL, too, which may be logical but it is probably too much.

Well, it's a bit annoying `struct commit::parents` is a `struct commit_list`, so we have to first check that pointer before we can dereference `item`, so that guard do we need anyway. So I agree it's too much.

One other thing, in v2 I'm also fixing the merge ancestor label. For root commits it will say "empty tree" instead of "parent of <commit>", so conflict messages aren't misleading.

-- 
Cheers,
Toon
Previous: Junio C HamanoNext: Toon Claes
Message 3 of 17 in “replay: support replaying down from root commit”
  1. replay: support replaying down from root commitToon Claes, Mar 17, 2026
  2. Junio C HamanoMar 17, 2026
  3. Toon ClaesMar 24, 2026
  4. replay: support replaying down from root commitToon Claes, Mar 24, 2026
  5. Junio C HamanoMar 24, 2026
  6. Christian CouderMar 25, 2026
  7. Ben KnobleMar 25, 2026
  8. Toon ClaesMar 25, 2026
  9. Toon ClaesMar 25, 2026
  10. Toon ClaesMar 25, 2026
  11. Junio C HamanoMar 27, 2026
  12. Christian CouderMar 31, 2026
  13. Junio C HamanoMar 31, 2026
  14. Toon ClaesApr 2, 2026
  15. Junio C HamanoApr 2, 2026
  16. Christian CouderApr 3, 2026
  17. Junio C HamanoMar 25, 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.