Subject: [PATCH v9 8/7] SQUASH ME: Fixups

From: Elijah Newren <[email-masked]>
Date: Sat, 10 Jan 2026 21:58:58 -0800

This includes several fixes I highlighted in my review and needs to be
split up and squashed into the relevant previous patches.

Signed-off-by: Elijah Newren <[email-masked]>
---
 Documentation/git-history.adoc |  2 +-
 builtin/history.c              | 16 ++++------------
 builtin/replay.c               | 10 ++--------
 replay.c                       | 10 ++++------
 replay.h                       | 21 +--------------------
 5 files changed, 12 insertions(+), 47 deletions(-)

diff --git a/Documentation/git-history.adoc b/Documentation/git-history.adoc
index 4eea317e5cb..457a1314a51 100644
--- a/Documentation/git-history.adoc
+++ b/Documentation/git-history.adoc
@@ -63,7 +63,7 @@ OPTIONS
 `--ref-action=(branches|head|print)`::
 	Control which references will be updated by the command, if any. With
 	`branches`, all local branches that point to commits which are
-	decendants of the original commit will be rewritten. With `head`, only
+	descendants of the original commit will be rewritten. With `head`, only
 	the current `HEAD` reference will be rewritten. With `print`, all
 	updates as they would be performed with `branches` are printed in a
 	format that can be consumed by linkgit:git-update-ref[1].
diff --git a/builtin/history.c b/builtin/history.c
index 28db6fc5b9e..60c5b5c5c76 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -178,9 +178,7 @@ static int handle_reference_updates(enum ref_action action,
 {
 	const struct name_decoration *decoration;
 	struct replay_revisions_options opts = { 0 };
-	struct replay_result result = {
-		.final_oid = rewritten->object.oid,
-	};
+	struct replay_result result = { 0 };
 	struct ref_transaction *transaction = NULL;
 	struct strvec args = STRVEC_INIT;
 	struct strbuf err = STRBUF_INIT;
@@ -233,7 +231,7 @@ static int handle_reference_updates(enum ref_action action,
 			goto out;
 		}
 
-		strvec_push(&args, oid_to_hex(&head->object.oid));
+		strvec_push(&args, "HEAD");
 	} else {
 		strvec_push(&args, "--branches");
 	}
@@ -244,13 +242,14 @@ static int handle_reference_updates(enum ref_action action,
 
 	opts.onto = oid_to_hex_r(hex, &rewritten->object.oid);
 
-	ret = replay_revisions(repo, &revs, &opts, &result);
+	ret = replay_revisions(&revs, &opts, &result);
 	if (ret)
 		goto out;
 
 	switch (action) {
 	case REF_ACTION_DEFAULT:
 	case REF_ACTION_BRANCHES:
+	case REF_ACTION_HEAD:
 		transaction = ref_store_transaction_begin(get_main_ref_store(repo), 0, &err);
 		if (!transaction) {
 			ret = error(_("failed to begin ref transaction: %s"), err.buf);
@@ -300,13 +299,6 @@ static int handle_reference_updates(enum ref_action action,
 		}
 
 		break;
-	case REF_ACTION_HEAD:
-		ret = refs_update_ref(get_main_ref_store(repo), reflog_msg, "HEAD",
-				      &result.final_oid, &head->object.oid, 0,
-				      UPDATE_REFS_MSG_ON_ERR);
-		if (ret)
-			goto out;
-		break;
 	case REF_ACTION_PRINT:
 		for (size_t i = 0; i < result.updates_nr; i++)
 			printf("update %s %s %s\n",
diff --git a/builtin/replay.c b/builtin/replay.c
index da8b7202f6a..f66e1a1fcd3 100644
--- a/builtin/replay.c
+++ b/builtin/replay.c
@@ -167,7 +167,7 @@ int cmd_replay(int argc,
 		revs.simplify_history = 0;
 	}
 
-	ret = replay_revisions(repo, &revs, &opts, &result);
+	ret = replay_revisions(&revs, &opts, &result);
 	if (ret)
 		goto cleanup;
 
@@ -220,11 +220,5 @@ int cmd_replay(int argc,
 	strbuf_release(&reflog_msg);
 	release_revisions(&revs);
 
-	if (ret) {
-		if (result.merge_conflict)
-			return 1;
-		return 128;
-	}
-
-	return 0;
+	return ret;
 }
diff --git a/replay.c b/replay.c
index 74e45ed27a2..ea300e3c36c 100644
--- a/replay.c
+++ b/replay.c
@@ -5,11 +5,11 @@
 #include "hex.h"
 #include "merge-ort.h"
 #include "object-name.h"
-#include "oidset.h"
 #include "parse-options.h"
 #include "refs.h"
 #include "replay.h"
 #include "revision.h"
+#include "strmap.h"
 #include "tree.h"
 
 static const char *short_commit_name(struct repository *repo,
@@ -256,7 +256,7 @@ static void replay_result_queue_update(struct replay_result *result,
 	result->updates_nr++;
 }
 
-int replay_revisions(struct repository *repo, struct rev_info *revs,
+int replay_revisions(struct rev_info *revs,
 		     struct replay_revisions_options *opts,
 		     struct replay_result *out)
 {
@@ -265,6 +265,7 @@ int replay_revisions(struct repository *repo, struct rev_info *revs,
 	struct commit *last_commit = NULL;
 	struct commit *commit;
 	struct commit *onto = NULL;
+	struct repository *repo = revs->repo;
 	struct merge_options merge_opt;
 	struct merge_result result = {
 		.clean = 1,
@@ -328,8 +329,7 @@ int replay_revisions(struct repository *repo, struct rev_info *revs,
 	}
 
 	if (!result.clean) {
-		out->merge_conflict = true;
-		ret = -1;
+		ret = 1;
 		goto out;
 	}
 
@@ -339,8 +339,6 @@ int replay_revisions(struct repository *repo, struct rev_info *revs,
 					   &onto->object.oid,
 					   &last_commit->object.oid);
 
-	out->final_oid = last_commit->object.oid;
-
 	ret = 0;
 
 out:
diff --git a/replay.h b/replay.h
index f8f9889112e..9b31c85dd9b 100644
--- a/replay.h
+++ b/replay.h
@@ -43,25 +43,6 @@ struct replay_result {
 		struct object_id new_oid;
 	} *updates;
 	size_t updates_nr, updates_alloc;
-
-	/* Set to true in case the replay failed with a merge conflict. */
-	bool merge_conflict;
-
-	/*
-	 * 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_result_release(struct replay_result *result);
@@ -73,7 +54,7 @@ void replay_result_release(struct replay_result *result);
  *
  * Returns 0 on success, a negative error code otherwise.
  */
-int replay_revisions(struct repository *repo, struct rev_info *revs,
+int replay_revisions(struct rev_info *revs,
 		     struct replay_revisions_options *opts,
 		     struct replay_result *out);
 
-- 
2.52.0.410.g227cdbe8e36