Skip to content

Commit 5f43cf5

Browse files
dschogitster
authored andcommitted
merge-tree: accept 3 trees as arguments
When specifying a merge base explicitly, there is actually no good reason why the inputs need to be commits: that's only needed if the merge base has to be deduced from the commit graph. This commit is best viewed with `--color-moved --color-moved-ws=allow-indentation-change`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564d025 commit 5f43cf5

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

Documentation/git-merge-tree.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ OPTIONS
6464
share no common history. This flag can be given to override that
6565
check and make the merge proceed anyway.
6666

67-
--merge-base=<commit>::
67+
--merge-base=<tree-ish>::
6868
Instead of finding the merge-bases for <branch1> and <branch2>,
6969
specify a merge-base for the merge, and specifying multiple bases is
7070
currently not supported. This option is incompatible with `--stdin`.
71+
+
72+
As the merge-base is provided directly, <branch1> and <branch2> do not need
73+
to specify commits; trees are enough.
7174

7275
[[OUTPUT]]
7376
OUTPUT

builtin/merge-tree.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,35 +430,43 @@ static int real_merge(struct merge_tree_options *o,
430430
struct merge_options opt;
431431

432432
copy_merge_options(&opt, &o->merge_options);
433-
parent1 = get_merge_parent(branch1);
434-
if (!parent1)
435-
help_unknown_ref(branch1, "merge-tree",
436-
_("not something we can merge"));
437-
438-
parent2 = get_merge_parent(branch2);
439-
if (!parent2)
440-
help_unknown_ref(branch2, "merge-tree",
441-
_("not something we can merge"));
442-
443433
opt.show_rename_progress = 0;
444434

445435
opt.branch1 = branch1;
446436
opt.branch2 = branch2;
447437

448438
if (merge_base) {
449-
struct commit *base_commit;
450439
struct tree *base_tree, *parent1_tree, *parent2_tree;
451440

452-
base_commit = lookup_commit_reference_by_name(merge_base);
453-
if (!base_commit)
454-
die(_("could not lookup commit '%s'"), merge_base);
441+
/*
442+
* We actually only need the trees because we already
443+
* have a merge base.
444+
*/
445+
struct object_id base_oid, head_oid, merge_oid;
446+
447+
if (repo_get_oid_treeish(the_repository, merge_base, &base_oid))
448+
die(_("could not parse as tree '%s'"), merge_base);
449+
base_tree = parse_tree_indirect(&base_oid);
450+
if (repo_get_oid_treeish(the_repository, branch1, &head_oid))
451+
die(_("could not parse as tree '%s'"), branch1);
452+
parent1_tree = parse_tree_indirect(&head_oid);
453+
if (repo_get_oid_treeish(the_repository, branch2, &merge_oid))
454+
die(_("could not parse as tree '%s'"), branch2);
455+
parent2_tree = parse_tree_indirect(&merge_oid);
455456

456457
opt.ancestor = merge_base;
457-
base_tree = repo_get_commit_tree(the_repository, base_commit);
458-
parent1_tree = repo_get_commit_tree(the_repository, parent1);
459-
parent2_tree = repo_get_commit_tree(the_repository, parent2);
460458
merge_incore_nonrecursive(&opt, base_tree, parent1_tree, parent2_tree, &result);
461459
} else {
460+
parent1 = get_merge_parent(branch1);
461+
if (!parent1)
462+
help_unknown_ref(branch1, "merge-tree",
463+
_("not something we can merge"));
464+
465+
parent2 = get_merge_parent(branch2);
466+
if (!parent2)
467+
help_unknown_ref(branch2, "merge-tree",
468+
_("not something we can merge"));
469+
462470
/*
463471
* Get the merge bases, in reverse order; see comment above
464472
* merge_incore_recursive in merge-ort.h

t/t4301-merge-tree-write-tree.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,4 +945,10 @@ test_expect_success 'check the input format when --stdin is passed' '
945945
test_cmp expect actual
946946
'
947947

948+
test_expect_success '--merge-base with tree OIDs' '
949+
git merge-tree --merge-base=side1^ side1 side3 >with-commits &&
950+
git merge-tree --merge-base=side1^^{tree} side1^{tree} side3^{tree} >with-trees &&
951+
test_cmp with-commits with-trees
952+
'
953+
948954
test_done

0 commit comments

Comments
 (0)