replay: add helper to put entry into replayed_commits

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Toon Claes committed Jul 28, 2026 at 17:45 UTC df94e2b767ddc1968d5cfff55b87d5aec923e8a7
1 file changed +20 -11
replay.c
+20 -11
@@ -254,9 +254,9 @@ static void set_up_replay_mode(struct repository *repo,
254 strset_clear(&rinfo.positive_refs);
255 }
256
257 -static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
258 - struct commit *commit,
259 - struct commit *fallback)
257 +static struct commit *get_mapped_commit(kh_oid_map_t *replayed_commits,
258 + struct commit *commit,
259 + struct commit *fallback)
260 {
261 khint_t pos;
262 if (!commit)
@@ -267,6 +267,21 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
267 return kh_value(replayed_commits, pos);
268 }
269
270 +static void put_mapped_commit(kh_oid_map_t *replayed_commits,
271 + struct commit *commit,
272 + struct commit *new_commit)
273 +{
274 + khint_t pos;
275 + int ret;
276 +
277 + pos = kh_put_oid_map(replayed_commits, commit->object.oid, &ret);
278 + if (ret == 0)
279 + BUG("Duplicate rewritten commit: %s",
280 + oid_to_hex(&commit->object.oid));
281 +
282 + kh_value(replayed_commits, pos) = new_commit;
283 +}
284 +
285 static struct commit *pick_regular_commit(struct repository *repo,
286 struct commit *pickme,
287 kh_oid_map_t *replayed_commits,
@@ -287,7 +302,7 @@ static struct commit *pick_regular_commit(struct repository *repo,
302 base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
303 }
304
290 - replayed_base = mapped_commit(replayed_commits, base, onto);
305 + replayed_base = get_mapped_commit(replayed_commits, base, onto);
306 replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
307 pickme_tree = repo_get_commit_tree(repo, pickme);
308
@@ -427,8 +442,6 @@ int replay_revisions(struct rev_info *revs,
442 replayed_commits = kh_init_oid_map();
443 while ((commit = get_revision(revs))) {
444 const struct name_decoration *decoration;
430 - khint_t pos;
431 - int hr;
445
446 if (commit->parents && commit->parents->next)
447 die(_("replaying merge commits is not supported yet!"));
@@ -440,11 +453,7 @@ int replay_revisions(struct rev_info *revs,
453 break;
454
455 /* Record commit -> last_commit mapping */
443 - pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
444 - if (hr == 0)
445 - BUG("Duplicate rewritten commit: %s\n",
446 - oid_to_hex(&commit->object.oid));
447 - kh_value(replayed_commits, pos) = last_commit;
456 + put_mapped_commit(replayed_commits, commit, last_commit);
457
458 /* Update any necessary branches */
459 if (ref)