summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyrie Vella <tyrielv@gmail.com>2018-01-22 14:44:31 -0800
committerPatrick Steinhardt <ps@pks.im>2018-03-10 17:45:25 +0000
commitb3c0d43cead12805800b20e84ab0129187a646d6 (patch)
treeba3e36acf0fbd381bd498f79b01d6903f3485ce8
parent3619e0f09f66afb9d0394b3a1e964edef9b9a40b (diff)
downloadlibgit2-b3c0d43cead12805800b20e84ab0129187a646d6.tar.gz
merge: virtual commit should be last argument to merge-base
Our virtual commit must be the last argument to merge-base: since our algorithm pushes _both_ parents of the virtual commit, it needs to be the last argument, since merge-base: > Given three commits A, B and C, git merge-base A B C will compute the > merge base between A and a hypothetical commit M We want to calculate the merge base between the actual commit ("two") and the virtual commit ("one") - since one actually pushes its parents to the merge-base calculation, we need to calculate the merge base of "two" and the parents of one.
-rw-r--r--src/merge.c10
-rw-r--r--tests/merge/trees/recursive.c4
2 files changed, 10 insertions, 4 deletions
diff --git a/src/merge.c b/src/merge.c
index 476a38ae5..a85b0a60c 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2149,8 +2149,14 @@ static int compute_base(
if (given_opts)
memcpy(&opts, given_opts, sizeof(git_merge_options));
- if ((error = insert_head_ids(&head_ids, one)) < 0 ||
- (error = insert_head_ids(&head_ids, two)) < 0 ||
+ /* With more than two commits, merge_bases_many finds the base of
+ * the first commit and a hypothetical merge of the others. Since
+ * "one" may itself be a virtual commit, which insert_head_ids
+ * substitutes multiple ancestors for, it needs to be added
+ * after "two" which is always a single real commit.
+ */
+ if ((error = insert_head_ids(&head_ids, two)) < 0 ||
+ (error = insert_head_ids(&head_ids, one)) < 0 ||
(error = git_merge_bases_many(&bases, repo,
head_ids.size, head_ids.ptr)) < 0)
goto done;
diff --git a/tests/merge/trees/recursive.c b/tests/merge/trees/recursive.c
index c84556514..d4defb898 100644
--- a/tests/merge/trees/recursive.c
+++ b/tests/merge/trees/recursive.c
@@ -422,7 +422,7 @@ void test_merge_trees_recursive__merge_base_for_virtual_commit(void)
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "1bde1883de4977ea3e664b315da951d1f614c3b1", 0, "targetfile.txt" },
- { 0100644, "b7de2b52ba055688061355fad1599a5d214ce8f8", 1, "version.txt" },
+ { 0100644, "f66647f02d6779e119bd435fe2908867c64c265f", 1, "version.txt" },
{ 0100644, "358efd6f589384fa8baf92234db9c7899a53916e", 2, "version.txt" },
{ 0100644, "a664873b1c0b9a1ed300f8644dde536fdaa3a34f", 3, "version.txt" },
};
@@ -445,7 +445,7 @@ void test_merge_trees_recursive__merge_base_for_virtual_commit_2(void)
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "4a06b258fed8a4d15967ec4253ae7366b70f727d", 0, "targetfile.txt" },
- { 0100644, "b6bd0f9952f396e757d3f91e08c59a7e91707201", 1, "version.txt" },
+ { 0100644, "16c5a7810777e1181709833cfe6931949259f802", 1, "version.txt" },
{ 0100644, "f0856993e005c0d8ed2dc7cdc222cc1d89fb3c77", 2, "version.txt" },
{ 0100644, "2cba583804a4a6fad1baf97c959be447238d1489", 3, "version.txt" },
};