]> git.ipfire.org Git - thirdparty/git.git/commitdiff
replay: add helper to put entry into replayed_commits
authorToon Claes <toon@iotcl.com>
Tue, 28 Jul 2026 15:45:51 +0000 (17:45 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jul 2026 18:27:41 +0000 (11:27 -0700)
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>
replay.c

index 463c900d6c7c56b6b2638fefd5976b8102e83b62..860e194ba064c9d537ce0def3044e96ccd89d438 100644 (file)
--- 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)