Skip to content

Commit dbec23a

Browse files
To1negitster
authored andcommitted
replay: add helper to put entry into mapped_commits
The function replay_revisions() in replay.c is rather lengthy. Extract the logic to put a commit entry into 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>
1 parent ea0af2f commit dbec23a

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

replay.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ static void set_up_replay_mode(struct repository *repo,
243243
strset_clear(&rinfo.positive_refs);
244244
}
245245

246-
static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
247-
struct commit *commit,
248-
struct commit *fallback)
246+
static struct commit *get_mapped_commit(kh_oid_map_t *replayed_commits,
247+
struct commit *commit,
248+
struct commit *fallback)
249249
{
250250
khint_t pos;
251251
if (!commit)
@@ -256,6 +256,21 @@ static struct commit *mapped_commit(kh_oid_map_t *replayed_commits,
256256
return kh_value(replayed_commits, pos);
257257
}
258258

259+
static void put_mapped_commit(kh_oid_map_t *replayed_commits,
260+
struct commit *commit,
261+
struct commit *new_commit)
262+
{
263+
khint_t pos;
264+
int ret;
265+
266+
pos = kh_put_oid_map(replayed_commits, commit->object.oid, &ret);
267+
if (ret == 0)
268+
BUG("Duplicate rewritten commit: %s\n",
269+
oid_to_hex(&commit->object.oid));
270+
271+
kh_value(replayed_commits, pos) = new_commit;
272+
}
273+
259274
static struct commit *pick_regular_commit(struct repository *repo,
260275
struct commit *pickme,
261276
kh_oid_map_t *replayed_commits,
@@ -276,7 +291,7 @@ static struct commit *pick_regular_commit(struct repository *repo,
276291
base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
277292
}
278293

279-
replayed_base = mapped_commit(replayed_commits, base, onto);
294+
replayed_base = get_mapped_commit(replayed_commits, base, onto);
280295
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
281296
pickme_tree = repo_get_commit_tree(repo, pickme);
282297

@@ -414,8 +429,6 @@ int replay_revisions(struct rev_info *revs,
414429
replayed_commits = kh_init_oid_map();
415430
while ((commit = get_revision(revs))) {
416431
const struct name_decoration *decoration;
417-
khint_t pos;
418-
int hr;
419432

420433
if (commit->parents && commit->parents->next)
421434
die(_("replaying merge commits is not supported yet!"));
@@ -427,11 +440,7 @@ int replay_revisions(struct rev_info *revs,
427440
break;
428441

429442
/* Record commit -> last_commit mapping */
430-
pos = kh_put_oid_map(replayed_commits, commit->object.oid, &hr);
431-
if (hr == 0)
432-
BUG("Duplicate rewritten commit: %s\n",
433-
oid_to_hex(&commit->object.oid));
434-
kh_value(replayed_commits, pos) = last_commit;
443+
put_mapped_commit(replayed_commits, commit, last_commit);
435444

436445
/* Update any necessary branches */
437446
if (ref)

0 commit comments

Comments
 (0)