merge-ort: support subtree shifting
merge-recursive has some simple code to support subtree shifting; copy it over to merge-ort. This fixes t6409.12 under GIT_TEST_MERGE_ALGORITHM=ort. Signed-off-by: Elijah Newren <newren@gmail.com> Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Mar 20, 2021 at 00:03 UTC
3639dfb3a8ea6935a7863fcbcc1c7a6c9104980e
1 file changed
+24
merge-ort.c
+24
@@ -3551,6 +3551,23 @@ void merge_finalize(struct merge_options *opt,
3551
3552
/*** Function Grouping: helper functions for merge_incore_*() ***/
3553
3554
+static struct tree *shift_tree_object(struct repository *repo,
3555
+ struct tree *one, struct tree *two,
3556
+ const char *subtree_shift)
3557
+{
3558
+ struct object_id shifted;
3559
+
3560
+ if (!*subtree_shift) {
3561
+ shift_tree(repo, &one->object.oid, &two->object.oid, &shifted, 0);
3562
+ } else {
3563
+ shift_tree_by(repo, &one->object.oid, &two->object.oid, &shifted,
3564
+ subtree_shift);
3565
+ }
3566
+ if (oideq(&two->object.oid, &shifted))
3567
+ return two;
3568
+ return lookup_tree(repo, &shifted);
3569
+}
3570
+
3571
static inline void set_commit_tree(struct commit *c, struct tree *t)
3572
{
3573
c->maybe_tree = t;
@@ -3680,6 +3697,13 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
3697
{
3698
struct object_id working_tree_oid;
3699
3700
+ if (opt->subtree_shift) {
3701
+ side2 = shift_tree_object(opt->repo, side1, side2,
3702
+ opt->subtree_shift);
3703
+ merge_base = shift_tree_object(opt->repo, side1, merge_base,
3704
+ opt->subtree_shift);
3705
+ }
3706
+
3707
trace2_region_enter("merge", "collect_merge_info", opt->repo);
3708
if (collect_merge_info(opt, merge_base, side1, side2) != 0) {
3709
/*