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

[PATCH v8 1/3] replay: add helper to put entry into replayed_commits

From
Toon Claes <toon@iotcl.com>
Date
Jul 28, 2026, 15:45 UTC
Message-ID
<20260728-toon-git-replay-drop-merges-v8-1-ced11dffe749@iotcl.com>
In-Reply-To
<20260728-toon-git-replay-drop-merges-v8-0-ced11dffe749@iotcl.com>

The function replay_revisions() in replay.c is rather lengthy. Extract the logic to put a commit entry into a `struct mapped_commits` into a helper function put_mapped_commit().

While at it, rename mapped_commit() to get_mapped_commit() to pair with this new function.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
 replay.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/replay.c b/replay.c
index 463c900d6c..860e194ba0 100644
--- a/replay.c
+++ b/replay.c
@@ -254,9 +254,9 @@ static void set_up_replay_mode(struct repository *repo,
 	strset_clear(&rinfo.positive_refs);
 }
 
-static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
-				    struct commit *commit,
-				    struct commit *fallback)
+static struct commit *get_mapped_commit(kh_oid_map_t *replayed_commits,
+					struct commit *commit,
+					struct commit *fallback)
 {
 	khint_t pos;
 	if (!commit)
@@ -267,6 +267,21 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
 	return kh_value(replayed_commits, pos);
 }
 
+static void put_mapped_commit(kh_oid_map_t *replayed_commits,
+			      struct commit *commit,
+			      struct commit *new_commit)
+{
+	khint_t pos;
+	int ret;
+
+	pos = kh_put_oid_map(replayed_commits, commit->object.oid, &ret);
+	if (ret == 0)
+		BUG("Duplicate rewritten commit: %s",
+		    oid_to_hex(&commit->object.oid));
+
+	kh_value(replayed_commits, pos) = new_commit;
+}
+
 static struct commit *pick_regular_commit(struct repository *repo,
 					  struct commit *pickme,
 					  kh_oid_map_t *replayed_commits,
@@ -287,7 +302,7 @@ static struct commit *pick_regular_commit(struct repository *repo,
 		base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
 	}
 
-	replayed_base = mapped_commit(replayed_commits, base, onto);
+	replayed_base = get_mapped_commit(replayed_commits, base, onto);
 	replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
 	pickme_tree = repo_get_commit_tree(repo, pickme);
 
@@ -427,8 +442,6 @@ int replay_revisions(struct rev_info *revs,
 	replayed_commits = kh_init_oid_map();
 	while ((commit = get_revision(revs))) {
 		const struct name_decoration *decoration;
-		khint_t pos;
-		int hr;
 
 		if (commit->parents && commit->parents->next)
 			die(_("replaying merge commits is not supported yet!"));
@@ -440,11 +453,7 @@ int replay_revisions(struct rev_info *revs,
 			break;
 
 		/* Record commit -> last_commit mapping */
-		pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
-		if (hr == 0)
-			BUG("Duplicate rewritten commit: %s\n",
-			    oid_to_hex(&commit->object.oid));
-		kh_value(replayed_commits, pos) = last_commit;
+		put_mapped_commit(replayed_commits, commit, last_commit);
 
 		/* Update any necessary branches */
 		if (ref)
-- 
2.55.0.424.g13c7afec21
Previous: Toon ClaesNext: Toon Claes
Message 64 of 75 in “Teach git-replay(1) to linearize merge commits”
  1. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jun 8, 2026
  2. 1/3 replay: refactor enum replay_mode into a boolToon Claes, Jun 8, 2026
  3. 2/3 replay: add helper to put entry into mapped_commitsToon Claes, Jun 8, 2026
  4. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jun 8, 2026
  5. Junio C HamanoJun 8, 2026
  6. Toon ClaesJun 10, 2026
  7. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jun 10, 2026
  8. 1/3 replay: refactor enum replay_mode into a boolToon Claes, Jun 10, 2026
  9. 2/3 replay: add helper to put entry into mapped_commitsToon Claes, Jun 10, 2026
  10. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jun 10, 2026
  11. Junio C HamanoJun 10, 2026
  12. Justin ToblerJun 11, 2026
  13. Toon ClaesJun 12, 2026
  14. Elijah NewrenJun 14, 2026
  15. Toon ClaesJun 16, 2026
  16. Toon ClaesJun 16, 2026
  17. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jun 16, 2026
  18. 1/3 replay: refactor enum replay_mode into a boolToon Claes, Jun 16, 2026
  19. 2/3 replay: add helper to put entry into mapped_commitsToon Claes, Jun 16, 2026
  20. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jun 16, 2026
  21. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jun 22, 2026
  22. 1/3 replay: refactor enum replay_mode into a boolToon Claes, Jun 22, 2026
  23. 2/3 replay: add helper to put entry into mapped_commitsToon Claes, Jun 22, 2026
  24. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jun 22, 2026
  25. Patrick SteinhardtJun 22, 2026
  26. Patrick SteinhardtJun 22, 2026
  27. Patrick SteinhardtJun 22, 2026
  28. Junio C HamanoJun 22, 2026
  29. Toon ClaesJun 24, 2026
  30. Toon ClaesJun 26, 2026
  31. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jun 26, 2026
  32. 1/3 replay: add helper to put entry into mapped_commitsToon Claes, Jun 26, 2026
  33. 2/3 replay: better explain how pick_regular_commit() picks a baseToon Claes, Jun 26, 2026
  34. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jun 26, 2026
  35. Junio C HamanoJun 26, 2026
  36. Junio C HamanoJun 26, 2026
  37. Phillip WoodJun 27, 2026
  38. Johannes SchindelinJun 28, 2026
  39. Patrick SteinhardtJun 29, 2026
  40. Johannes SchindelinJun 30, 2026
  41. Patrick SteinhardtJun 30, 2026
  42. Toon ClaesJun 30, 2026
  43. Toon ClaesJul 1, 2026
  44. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jul 2, 2026
  45. 1/3 replay: add helper to put entry into replayed_commitsToon Claes, Jul 2, 2026
  46. 2/3 replay: resolve the replay base outside pick_regular_commit()Toon Claes, Jul 2, 2026
  47. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jul 2, 2026
  48. Junio C HamanoJul 3, 2026
  49. Toon ClaesJul 7, 2026
  50. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jul 7, 2026
  51. 1/3 replay: add helper to put entry into replayed_commitsToon Claes, Jul 7, 2026
  52. 2/3 replay: resolve the replay base outside pick_regular_commit()Toon Claes, Jul 7, 2026
  53. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jul 7, 2026
  54. Junio C HamanoJul 7, 2026
  55. Junio C HamanoJul 8, 2026
  56. Elijah NewrenJul 10, 2026
  57. Junio C HamanoJul 13, 2026
  58. Elijah NewrenJul 15, 2026
  59. Junio C HamanoJul 15, 2026
  60. Elijah NewrenJul 16, 2026
  61. Junio C HamanoJul 17, 2026
  62. Toon ClaesJul 27, 2026
  63. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Jul 28, 2026
  64. 1/3 replay: add helper to put entry into replayed_commitsToon Claes, Jul 28, 2026
  65. 2/3 replay: resolve the replay base outside pick_regular_commit()Toon Claes, Jul 28, 2026
  66. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Jul 28, 2026
  67. Junio C HamanoJul 28, 2026
  68. Justin ToblerAug 7, 2026
  69. Elijah NewrenAug 8, 2026
  70. Toon ClaesAug 31, 2026
  71. 0/3 Teach git-replay(1) to linearize merge commitsToon Claes, Aug 31, 2026
  72. 1/3 replay: add helper to put entry into replayed_commitsToon Claes, Aug 31, 2026
  73. 2/3 replay: resolve the replay base outside pick_regular_commit()Toon Claes, Aug 31, 2026
  74. 3/3 replay: offer an option to linearize the commit topologyToon Claes, Aug 31, 2026
  75. Elijah NewrenSep 1, 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.