1578
return 0;
1579
}
1580
1581
-/**
1582
- * Do the three-way merge using fake ancestor, their tree constructed
1583
- * from the fake ancestor and the postimage of the patch, and our
1584
- * state.
1585
- */
1586
-static int run_fallback_merge_recursive(const struct am_state *state,
1587
- unsigned char *orig_tree,
1588
- unsigned char *our_tree,
1589
- unsigned char *their_tree)
1590
-{
1591
- struct child_process cp = CHILD_PROCESS_INIT;
1592
- int status;
1593
-
1594
- cp.git_cmd = 1;
1595
-
1596
- argv_array_pushf(&cp.env_array, "GITHEAD_%s=%.*s",
1597
- sha1_to_hex(their_tree), linelen(state->msg), state->msg);
1598
- if (state->quiet)
1599
- argv_array_push(&cp.env_array, "GIT_MERGE_VERBOSITY=0");
1600
-
1601
- argv_array_push(&cp.args, "merge-recursive");
1602
- argv_array_push(&cp.args, sha1_to_hex(orig_tree));
1603
- argv_array_push(&cp.args, "--");
1604
- argv_array_push(&cp.args, sha1_to_hex(our_tree));
1605
- argv_array_push(&cp.args, sha1_to_hex(their_tree));
1606
-
1607
- status = run_command(&cp) ? (-1) : 0;
1608
- discard_cache();
1609
- read_cache();
1610
- return status;
1611
-}
1612
-
1581
/**
1582
* Attempt a threeway merge, using index_path as the temporary index.
1583
*/
1584
static int fall_back_threeway(const struct am_state *state, const char *index_path)
1585
{
1618
- unsigned char orig_tree[GIT_SHA1_RAWSZ], their_tree[GIT_SHA1_RAWSZ],
1619
- our_tree[GIT_SHA1_RAWSZ];
1586
+ struct object_id orig_tree, their_tree, our_tree;
1587
+ const struct object_id *bases[1] = { &orig_tree };
1588
+ struct merge_options o;
1589
+ struct commit *result;
1590
+ char *their_tree_name;
1591
1621
- if (get_sha1("HEAD", our_tree) < 0)
1622
- hashcpy(our_tree, EMPTY_TREE_SHA1_BIN);
1592
+ if (get_oid("HEAD", &our_tree) < 0)
1593
+ hashcpy(our_tree.hash, EMPTY_TREE_SHA1_BIN);
1594
1595
if (build_fake_ancestor(state, index_path))
1596
return error("could not build fake ancestor");
1598
discard_cache();
1599
read_cache_from(index_path);
1600
1630
- if (write_index_as_tree(orig_tree, &the_index, index_path, 0, NULL))
1601
+ if (write_index_as_tree(orig_tree.hash, &the_index, index_path, 0, NULL))
1602
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
1603
1604
say(state, stdout, _("Using index info to reconstruct a base tree..."));
1614
init_revisions(&rev_info, NULL);
1615
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
1616
diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
1646
- add_pending_sha1(&rev_info, "HEAD", our_tree, 0);
1617
+ add_pending_sha1(&rev_info, "HEAD", our_tree.hash, 0);
1618
diff_setup_done(&rev_info.diffopt);
1619
run_diff_index(&rev_info, 1);
1620
}
1623
return error(_("Did you hand edit your patch?\n"
1624
"It does not apply to blobs recorded in its index."));
1625
1655
- if (write_index_as_tree(their_tree, &the_index, index_path, 0, NULL))
1626
+ if (write_index_as_tree(their_tree.hash, &the_index, index_path, 0, NULL))
1627
return error("could not write tree");
1628
1629
say(state, stdout, _("Falling back to patching base and 3-way merge..."));
1639
* changes.
1640
*/
1641
1671
- if (run_fallback_merge_recursive(state, orig_tree, our_tree, their_tree)) {
1642
+ init_merge_options(&o);
1643
+
1644
+ o.branch1 = "HEAD";
1645
+ their_tree_name = xstrfmt("%.*s", linelen(state->msg), state->msg);
1646
+ o.branch2 = their_tree_name;
1647
+
1648
+ if (state->quiet)
1649
+ o.verbosity = 0;
1650
+
1651
+ if (merge_recursive_generic(&o, &our_tree, &their_tree, 1, bases, &result)) {
1652
rerere(state->allow_rerere_autoupdate);
1653
+ free(their_tree_name);
1654
return error(_("Failed to merge in the changes."));
1655
}
1656
1657
+ free(their_tree_name);
1658
return 0;
1659
}
1660