]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replay: yield the object ID of the final rewritten commit
authorPatrick Steinhardt <ps@pks.im>
Wed, 7 Jan 2026 10:10:12 +0000 (11:10 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Jan 2026 02:01:59 +0000 (11:01 +0900)
In a subsequent commit we'll introduce a new git-history(1) command that
uses the replay machinery to rewrite commits. One of its supported modes
will only want to update the "HEAD" reference, but that is not currently
supported by the replay machinery.

Allow implementing this use case by exposing a `final_oid` field for the
reference updates. This field will be set to the last commit that was
rewritten, which is sufficient information for us to implement this mode
in git-history(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
replay.c
replay.h

index 367951395a70256d060799b3c47ab039326d58fa..8c2f2d3710110b255da2119775728e7c8a22361f 100644 (file)
--- a/replay.c
+++ b/replay.c
@@ -330,6 +330,8 @@ int replay_revisions(struct repository *repo, struct rev_info *revs,
                updates->nr++;
        }
 
+       updates->final_oid = last_commit->object.oid;
+
        ret = 0;
 
 out:
index bc7a321a5ea31c449edaf4f2af0cbd49f682fb09..e00bb4214e20acd2c08ba84ca9e1dbfc04a67794 100644 (file)
--- a/replay.h
+++ b/replay.h
@@ -43,6 +43,22 @@ struct replay_ref_updates {
                struct object_id new_oid;
        } *items;
        size_t nr, alloc;
+
+       /*
+        * The final object ID that was rewritten. Note that this field has
+        * somewhat special semantics and may or may not be what you want:
+        *
+        *   - If no commits were rewritten it will remain uninitialized.
+        *
+        *   - If a thicket of branches is rewritten it is undefined in which
+        *     order those branches will be rewritten, and thus the final object
+        *     ID may point to a different commit than you'd expect.
+        *
+        * That being said, this field can still be useful when you know that
+        * you only replay a single strand of commits. In that case, the final
+        * commit will point to the tip of the rewritten strand of commits.
+        */
+       struct object_id final_oid;
 };
 
 void replay_ref_updates_release(struct replay_ref_updates *updates);