* [PATCH v1] replay.c: support replaying root commits
@ 2026-03-27 18:09 Tian Yuchen
2026-03-27 18:28 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Tian Yuchen @ 2026-03-27 18:09 UTC (permalink / raw)
To: git; +Cc: Tian Yuchen
'git replay' does not support replaying root commits, as indicated by
the FIXME comment. If a user attempts to replay a root commit, the 'die()'
in 'replay_revisions()' will be called.
The reason for this is that the call 'base = pickme->parents->item' in
'pick_regular_commit()' will cause a null pointer dereference error in the
case of a root commit.
Fix this by adding new conditional statements: the difference between the
root commit its 'common ancestor' is equivalent to the difference from
an empty tree object, and it must be placed on the user-specified target
branch 'onto'. Therefore, We set 'base' to 'NULL', 'replayed_base' to
'onto', and use 'lookup_tree()' to instantiate the OID of the empty tree
in order to pass it to 'base_tree'.
Signed-off-by: Tian Yuchen <cat@malon.dev>
---
To be honest, I'm not sure whether setting 'base = NULL' is proper or
not. Feel free to give feedback and suggestions!
replay.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/replay.c b/replay.c
index a63f6714c4..80497191a8 100644
--- a/replay.c
+++ b/replay.c
@@ -225,12 +225,21 @@ static struct commit *pick_regular_commit(struct repository *repo,
struct commit *base, *replayed_base;
struct tree *pickme_tree, *base_tree, *replayed_base_tree;
- 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);
+ } else {
+ /*
+ * Root commits have no parents. Their base is the empty tree,
+ * and they should be replayed directly onto the target 'onto' commit.
+ */
+ base = NULL;
+ replayed_base = onto;
+ base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
+ }
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
pickme_tree = repo_get_commit_tree(repo, pickme);
- base_tree = repo_get_commit_tree(repo, base);
merge_opt->branch1 = short_commit_name(repo, replayed_base);
merge_opt->branch2 = short_commit_name(repo, pickme);
@@ -293,8 +302,6 @@ int replay_revisions(struct rev_info *revs,
set_up_replay_mode(revs->repo, &revs->cmdline, opts->onto,
&detached_head, &advance, &onto, &update_refs);
- /* FIXME: Should allow replaying commits with the first as a root commit */
-
if (prepare_revision_walk(revs) < 0) {
ret = error(_("error preparing revisions"));
goto out;
@@ -309,9 +316,7 @@ int replay_revisions(struct rev_info *revs,
khint_t pos;
int hr;
- if (!commit->parents)
- die(_("replaying down from root commit is not supported yet!"));
- if (commit->parents->next)
+ if (commit->parents && commit->parents->next)
die(_("replaying merge commits is not supported yet!"));
last_commit = pick_regular_commit(revs->repo, commit, replayed_commits,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] replay.c: support replaying root commits
2026-03-27 18:09 [PATCH v1] replay.c: support replaying root commits Tian Yuchen
@ 2026-03-27 18:28 ` Junio C Hamano
2026-03-27 18:55 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2026-03-27 18:28 UTC (permalink / raw)
To: Tian Yuchen; +Cc: git
Tian Yuchen <cat@malon.dev> writes:
> 'git replay' does not support replaying root commits, as indicated by
> the FIXME comment. If a user attempts to replay a root commit, the 'die()'
> in 'replay_revisions()' will be called.
Please be aware of your surroundings. I think there are multiple
topics that work on this file and among them there is a topic to
address the same issue, if I am not mistaken.
The list archive is your friend, for example, you can try these:
https://lore.kernel.org/git/?q=replay+root
https://lore.kernel.org/git/?q=dfn%3Areplay.c+%22root+commit%22
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] replay.c: support replaying root commits
2026-03-27 18:28 ` Junio C Hamano
@ 2026-03-27 18:55 ` Junio C Hamano
2026-03-28 3:24 ` Tian Yuchen
0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2026-03-27 18:55 UTC (permalink / raw)
To: Tian Yuchen; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> Tian Yuchen <cat@malon.dev> writes:
>
>> 'git replay' does not support replaying root commits, as indicated by
>> the FIXME comment. If a user attempts to replay a root commit, the 'die()'
>> in 'replay_revisions()' will be called.
>
> Please be aware of your surroundings. I think there are multiple
> topics that work on this file and among them there is a topic to
> address the same issue, if I am not mistaken.
>
> The list archive is your friend, for example, you can try these:
>
> https://lore.kernel.org/git/?q=replay+root
> https://lore.kernel.org/git/?q=dfn%3Areplay.c+%22root+commit%22
>
> Thanks.
Oops, sent without completing what I needed to say.
After you find out that other people are working in the vicinity,
some of them even may be working on the same itch you had, instead
of silently letting them continue, join the conversation and help
them polish their work. You can give reviews, you can supply test
cases, you can polish their documentation, etc.
Let's make this a team effort, not authors completing against each
other, or authors working on their own thing without paying any
attention to what others are doing.
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] replay.c: support replaying root commits
2026-03-27 18:55 ` Junio C Hamano
@ 2026-03-28 3:24 ` Tian Yuchen
0 siblings, 0 replies; 4+ messages in thread
From: Tian Yuchen @ 2026-03-28 3:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Hi Junio,
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Tian Yuchen <cat@malon.dev> writes:
>>
>>> 'git replay' does not support replaying root commits, as indicated by
>>> the FIXME comment. If a user attempts to replay a root commit, the
>>> 'die()'
>>> in 'replay_revisions()' will be called.
>>
>> Please be aware of your surroundings. I think there are multiple
>> topics that work on this file and among them there is a topic to
>> address the same issue, if I am not mistaken.
>>
>> The list archive is your friend, for example, you can try these:
>>
>> https://lore.kernel.org/git/?q=replay+root
>> https://lore.kernel.org/git/?q=dfn%3Areplay.c+%22root+commit%22
>>
>> Thanks.
>
> Oops, sent without completing what I needed to say.
>
> After you find out that other people are working in the vicinity,
> some of them even may be working on the same itch you had, instead
> of silently letting them continue, join the conversation and help
> them polish their work. You can give reviews, you can supply test
> cases, you can polish their documentation, etc.
>
> Let's make this a team effort, not authors completing against each
> other, or authors working on their own thing without paying any
> attention to what others are doing.
>
> Thanks.
Oops, looks like I missed a few threads. Before I started, I actually
searched the mailing list to see if anyone else was working on this,
maybe I used the wrong keywords.
Thanks for pointing out. I'll join the discussion. ;)
Regards, Yuchen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-28 3:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27 18:09 [PATCH v1] replay.c: support replaying root commits Tian Yuchen
2026-03-27 18:28 ` Junio C Hamano
2026-03-27 18:55 ` Junio C Hamano
2026-03-28 3:24 ` Tian Yuchen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox