Commit
98b33a62f604c608ae2648750de767b23e961e67
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 <toon@iotcl.com> · 2026-08-31 13:13 UTC · committed by Junio C Hamano
1 file changed,
+20
−11
modified replay.c
| @@ -254,9 +254,9 @@ static void set_up_replay_mode(struct repository *repo, | |||
| 254 | 254 | strset_clear(&rinfo.positive_refs); | |
| 255 | 255 | } | |
| 256 | 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 | 260 | { | |
| 261 | 261 | khint_t pos; | |
| 262 | 262 | if (!commit) | |
| @@ -267,6 +267,21 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits, | |||
| 267 | 267 | return kh_value(replayed_commits, pos); | |
| 268 | 268 | } | |
| 269 | 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 | + | ||
| 270 | 285 | static struct commit *pick_regular_commit(struct repository *repo, | |
| 271 | 286 | struct commit *pickme, | |
| 272 | 287 | kh_oid_map_t *replayed_commits, | |
| @@ -287,7 +302,7 @@ static struct commit *pick_regular_commit(struct repository *repo, | |||
| 287 | 302 | base_tree = lookup_tree(repo, repo->hash_algo->empty_tree); | |
| 288 | 303 | } | |
| 289 | 304 | ||
| 290 | - | replayed_base = mapped_commit(replayed_commits, base, onto); | |
| 305 | + | replayed_base = get_mapped_commit(replayed_commits, base, onto); | |
| 291 | 306 | replayed_base_tree = repo_get_commit_tree(repo, replayed_base); | |
| 292 | 307 | pickme_tree = repo_get_commit_tree(repo, pickme); | |
| 293 | 308 | ||
| @@ -427,8 +442,6 @@ int replay_revisions(struct rev_info *revs, | |||
| 427 | 442 | replayed_commits = kh_init_oid_map(); | |
| 428 | 443 | while ((commit = get_revision(revs))) { | |
| 429 | 444 | const struct name_decoration *decoration; | |
| 430 | - | khint_t pos; | |
| 431 | - | int hr; | |
| 432 | 445 | ||
| 433 | 446 | if (commit->parents && commit->parents->next) | |
| 434 | 447 | die(_("replaying merge commits is not supported yet!")); | |
| @@ -440,11 +453,7 @@ int replay_revisions(struct rev_info *revs, | |||
| 440 | 453 | break; | |
| 441 | 454 | ||
| 442 | 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); | |
| 448 | 457 | ||
| 449 | 458 | /* Update any necessary branches */ | |
| 450 | 459 | if (ref) | |