{"thread":{"id":"65370","subject":"[PATCH v1] replay.c: support replaying root commits","startedAt":"2026-03-27T18:09:48Z","lastAt":"2026-03-28T03:25:06Z","messageCount":4,"participants":["Tian Yuchen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"540212","messageId":"20260327180930.104563-1-cat@malon.dev","threadId":"65370","inReplyTo":null,"subject":"[PATCH v1] replay.c: support replaying root commits","fromName":"Tian Yuchen","fromEmail":"cat@malon.dev","sentAt":"2026-03-27T18:09:30Z","receivedAt":"2026-03-27T18:09:48Z","isPatch":true,"sender":{"key":"cat@malon.dev","avatar":null},"body":"'git replay' does not support replaying root commits, as indicated by\nthe FIXME comment. If a user attempts to replay a root commit, the 'die()'\nin 'replay_revisions()' will be called.\n\nThe reason for this is that the call 'base = pickme->parents->item' in\n'pick_regular_commit()' will cause a null pointer dereference error in the\ncase of a root commit.\n\nFix this by adding new conditional statements: the difference between the\nroot commit its 'common ancestor' is equivalent to the difference from\nan empty tree object, and it must be placed on the user-specified target\nbranch 'onto'. Therefore,  We set 'base' to 'NULL', 'replayed_base' to\n'onto', and use 'lookup_tree()' to instantiate the OID of the empty tree\nin order to pass it to 'base_tree'.\n\nSigned-off-by: Tian Yuchen <cat@malon.dev>\n---\n\nTo be honest, I'm not sure whether setting 'base = NULL' is proper or\nnot. Feel free to give feedback and suggestions!\n\n replay.c | 23 ++++++++++++++---------\n 1 file changed, 14 insertions(+), 9 deletions(-)\n\ndiff --git a/replay.c b/replay.c\nindex a63f6714c4..80497191a8 100644\n--- a/replay.c\n+++ b/replay.c\n@@ -225,12 +225,21 @@ static struct commit *pick_regular_commit(struct repository *repo,\n \tstruct commit *base, *replayed_base;\n \tstruct tree *pickme_tree, *base_tree, *replayed_base_tree;\n \n-\tbase = pickme->parents->item;\n-\treplayed_base = mapped_commit(replayed_commits, base, onto);\n-\n+\tif (pickme->parents) {\n+\t\tbase = pickme->parents->item;\n+\t\treplayed_base = mapped_commit(replayed_commits, base, onto);\n+\t\tbase_tree = repo_get_commit_tree(repo, base);\n+\t} else {\n+\t\t/* \n+\t\t * Root commits have no parents. Their base is the empty tree,\n+\t\t * and they should be replayed directly onto the target 'onto' commit.\n+\t\t */\n+\t\tbase = NULL;\n+\t\treplayed_base = onto;\n+\t\tbase_tree = lookup_tree(repo, repo->hash_algo->empty_tree);\n+\t}\n \treplayed_base_tree = repo_get_commit_tree(repo, replayed_base);\n \tpickme_tree = repo_get_commit_tree(repo, pickme);\n-\tbase_tree = repo_get_commit_tree(repo, base);\n \n \tmerge_opt->branch1 = short_commit_name(repo, replayed_base);\n \tmerge_opt->branch2 = short_commit_name(repo, pickme);\n@@ -293,8 +302,6 @@ int replay_revisions(struct rev_info *revs,\n \tset_up_replay_mode(revs->repo, &revs->cmdline, opts->onto,\n \t\t\t   &detached_head, &advance, &onto, &update_refs);\n \n-\t/* FIXME: Should allow replaying commits with the first as a root commit */\n-\n \tif (prepare_revision_walk(revs) < 0) {\n \t\tret = error(_(\"error preparing revisions\"));\n \t\tgoto out;\n@@ -309,9 +316,7 @@ int replay_revisions(struct rev_info *revs,\n \t\tkhint_t pos;\n \t\tint hr;\n \n-\t\tif (!commit->parents)\n-\t\t\tdie(_(\"replaying down from root commit is not supported yet!\"));\n-\t\tif (commit->parents->next)\n+\t\tif (commit->parents && commit->parents->next)\n \t\t\tdie(_(\"replaying merge commits is not supported yet!\"));\n \n \t\tlast_commit = pick_regular_commit(revs->repo, commit, replayed_commits,\n-- \n2.43.0\n\n"},{"id":"540214","messageId":"xmqqh5q1jfdg.fsf@gitster.g","threadId":"65370","inReplyTo":"20260327180930.104563-1-cat@malon.dev","subject":"Re: [PATCH v1] replay.c: support replaying root commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-03-27T18:28:59Z","receivedAt":"2026-03-27T18:29:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":null},"body":"Tian Yuchen <cat@malon.dev> writes:\n\n> 'git replay' does not support replaying root commits, as indicated by\n> the FIXME comment. If a user attempts to replay a root commit, the 'die()'\n> in 'replay_revisions()' will be called.\n\nPlease be aware of your surroundings.  I think there are multiple\ntopics that work on this file and among them there is a topic to\naddress the same issue, if I am not mistaken.\n\nThe list archive is your friend, for example, you can try these:\n\n    https://lore.kernel.org/git/?q=replay+root\n    https://lore.kernel.org/git/?q=dfn%3Areplay.c+%22root+commit%22\n\nThanks.\n"},{"id":"540216","messageId":"xmqqcy0pje5c.fsf@gitster.g","threadId":"65370","inReplyTo":"xmqqh5q1jfdg.fsf@gitster.g","subject":"Re: [PATCH v1] replay.c: support replaying root commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-03-27T18:55:27Z","receivedAt":"2026-03-27T18:55:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Tian Yuchen <cat@malon.dev> writes:\n>\n>> 'git replay' does not support replaying root commits, as indicated by\n>> the FIXME comment. If a user attempts to replay a root commit, the 'die()'\n>> in 'replay_revisions()' will be called.\n>\n> Please be aware of your surroundings.  I think there are multiple\n> topics that work on this file and among them there is a topic to\n> address the same issue, if I am not mistaken.\n>\n> The list archive is your friend, for example, you can try these:\n>\n>     https://lore.kernel.org/git/?q=replay+root\n>     https://lore.kernel.org/git/?q=dfn%3Areplay.c+%22root+commit%22\n>\n> Thanks.\n\nOops, sent without completing what I needed to say.\n\nAfter you find out that other people are working in the vicinity,\nsome of them even may be working on the same itch you had, instead\nof silently letting them continue, join the conversation and help\nthem polish their work.  You can give reviews, you can supply test\ncases, you can polish their documentation, etc.\n\nLet's make this a team effort, not authors completing against each\nother, or authors working on their own thing without paying any\nattention to what others are doing.\n\nThanks.\n"},{"id":"540258","messageId":"283d016a1f109129e462b547e604a724@purelymail.com","threadId":"65370","inReplyTo":"xmqqcy0pje5c.fsf@gitster.g","subject":"Re: [PATCH v1] replay.c: support replaying root commits","fromName":"Tian Yuchen","fromEmail":"cat@malon.dev","sentAt":"2026-03-28T03:24:57Z","receivedAt":"2026-03-28T03:25:06Z","isPatch":true,"sender":{"key":"cat@malon.dev","avatar":null},"body":"Hi Junio,\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> \n>> Tian Yuchen <cat@malon.dev> writes:\n>> \n>>> 'git replay' does not support replaying root commits, as indicated by\n>>> the FIXME comment. If a user attempts to replay a root commit, the \n>>> 'die()'\n>>> in 'replay_revisions()' will be called.\n>> \n>> Please be aware of your surroundings.  I think there are multiple\n>> topics that work on this file and among them there is a topic to\n>> address the same issue, if I am not mistaken.\n>> \n>> The list archive is your friend, for example, you can try these:\n>> \n>>     https://lore.kernel.org/git/?q=replay+root\n>>     https://lore.kernel.org/git/?q=dfn%3Areplay.c+%22root+commit%22\n>> \n>> Thanks.\n> \n> Oops, sent without completing what I needed to say.\n> \n> After you find out that other people are working in the vicinity,\n> some of them even may be working on the same itch you had, instead\n> of silently letting them continue, join the conversation and help\n> them polish their work.  You can give reviews, you can supply test\n> cases, you can polish their documentation, etc.\n> \n> Let's make this a team effort, not authors completing against each\n> other, or authors working on their own thing without paying any\n> attention to what others are doing.\n> \n> Thanks.\n\nOops, looks like I missed a few threads. Before I started, I actually\nsearched the mailing list to see if anyone else was working on this,\nmaybe I used the wrong keywords.\n\nThanks for pointing out. I'll join the discussion. ;)\n\nRegards, Yuchen\n"}]}