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 7, 2026 at 21:07 UTC
4ae2ac8153e98568cfd6efed0e94a239db113ca6
1 file changed
+20
-11
replay.c
+20
-11
@@ -250,9 +250,9 @@ static void set_up_replay_mode(struct repository *repo,
250
strset_clear(&rinfo.positive_refs);
251
}
252
253
-static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
254
- struct commit *commit,
255
- struct commit *fallback)
253
+static struct commit *get_mapped_commit(kh_oid_map_t *replayed_commits,
254
+ struct commit *commit,
255
+ struct commit *fallback)
256
{
257
khint_t pos;
258
if (!commit)
@@ -263,6 +263,21 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
263
return kh_value(replayed_commits, pos);
264
}
265
266
+static void put_mapped_commit(kh_oid_map_t *replayed_commits,
267
+ struct commit *commit,
268
+ struct commit *new_commit)
269
+{
270
+ khint_t pos;
271
+ int ret;
272
+
273
+ pos = kh_put_oid_map(replayed_commits, commit->object.oid, &ret);
274
+ if (ret == 0)
275
+ BUG("Duplicate rewritten commit: %s",
276
+ oid_to_hex(&commit->object.oid));
277
+
278
+ kh_value(replayed_commits, pos) = new_commit;
279
+}
280
+
281
static struct commit *pick_regular_commit(struct repository *repo,
282
struct commit *pickme,
283
kh_oid_map_t *replayed_commits,
@@ -283,7 +298,7 @@ static struct commit *pick_regular_commit(struct repository *repo,
298
base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
299
}
300
286
- replayed_base = mapped_commit(replayed_commits, base, onto);
301
+ replayed_base = get_mapped_commit(replayed_commits, base, onto);
302
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
303
pickme_tree = repo_get_commit_tree(repo, pickme);
304
@@ -423,8 +438,6 @@ int replay_revisions(struct rev_info *revs,
438
replayed_commits = kh_init_oid_map();
439
while ((commit = get_revision(revs))) {
440
const struct name_decoration *decoration;
426
- khint_t pos;
427
- int hr;
441
442
if (commit->parents && commit->parents->next)
443
die(_("replaying merge commits is not supported yet!"));
@@ -436,11 +449,7 @@ int replay_revisions(struct rev_info *revs,
449
break;
450
451
/* Record commit -> last_commit mapping */
439
- pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
440
- if (hr == 0)
441
- BUG("Duplicate rewritten commit: %s\n",
442
- oid_to_hex(&commit->object.oid));
443
- kh_value(replayed_commits, pos) = last_commit;
452
+ put_mapped_commit(replayed_commits, commit, last_commit);
453
454
/* Update any necessary branches */
455
if (ref)