280
281
static struct commit *pick_regular_commit(struct repository *repo,
282
struct commit *pickme,
283
- kh_oid_map_t *replayed_commits,
284
- struct commit *onto,
283
+ struct commit *replayed_base,
284
struct merge_options *merge_opt,
285
struct merge_result *result,
286
enum replay_mode mode,
287
enum replay_empty_commit_action empty)
288
{
290
- struct commit *base, *replayed_base;
289
struct tree *pickme_tree, *base_tree, *replayed_base_tree;
290
293
- if (pickme->parents) {
294
- base = pickme->parents->item;
295
- base_tree = repo_get_commit_tree(repo, base);
296
- } else {
297
- base = NULL;
291
+ if (pickme->parents)
292
+ base_tree = repo_get_commit_tree(repo, pickme->parents->item);
293
+ else
294
base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
299
- }
295
301
- replayed_base = get_mapped_commit(replayed_commits, base, onto);
296
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
297
pickme_tree = repo_get_commit_tree(repo, pickme);
298
433
while ((commit = get_revision(revs))) {
434
const struct name_decoration *decoration;
435
436
+ /*
437
+ * Decide where to replay this commit on.
438
+ * If the parent commit was replayed already, the replayed result
439
+ * can be found in `replayed_commits`. Otherwise fall back to `onto`.
440
+ * When reverting, commits are replayed in reverse order and thus
441
+ * its parent isn't replayed yet. Therefore revert commits are
442
+ * always replayed onto `last_commit`.
443
+ */
444
+ struct commit *parent = commit->parents ? commit->parents->item : NULL;
445
+ struct commit *base = get_mapped_commit(replayed_commits, parent, onto);
446
+
447
+ if (mode == REPLAY_MODE_REVERT)
448
+ base = last_commit;
449
+
450
if (commit->parents && commit->parents->next)
451
die(_("replaying merge commits is not supported yet!"));
452
445
- last_commit = pick_regular_commit(revs->repo, commit, replayed_commits,
446
- mode == REPLAY_MODE_REVERT ? last_commit : onto,
447
- &merge_opt, &result, mode, opts->empty);
453
+ last_commit = pick_regular_commit(revs->repo, commit, base,
454
+ &merge_opt, &result,
455
+ mode, opts->empty);
456
if (!last_commit)
457
break;
458