summaryrefslogtreecommitdiffstats
path: root/merge-recursive.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2018-10-16 13:19:48 -0700
committerJunio C Hamano <gitster@pobox.com>2018-10-18 14:45:39 +0900
commit4f445453136b8c3575bc4d4c45fc9b7930688a5c (patch)
tree3c775134988ef6cdb720fecb6dc39b039d5898d3 /merge-recursive.c
parent2b168ef3ffa308537d858b9910170e4d314a8f4a (diff)
downloadgit-4f445453136b8c3575bc4d4c45fc9b7930688a5c.tar.gz
git-4f445453136b8c3575bc4d4c45fc9b7930688a5c.tar.xz
merge-recursive: avoid showing conflicts with merge branch before HEAD
We want to load unmerged entries from HEAD into the index at stage 2 and from MERGE_HEAD into stage 3. Similarly, folks expect merge conflicts to look like <<<<<<<< HEAD content from our side ======== content from their side >>>>>>>> MERGE_HEAD not <<<<<<<< MERGE_HEAD content from their side ======== content from our side >>>>>>>> HEAD The correct order usually comes naturally and for free, but with renames we often have data in the form {rename_branch, other_branch}, and working relative to the rename first (e.g. for rename/add) is more convenient elsewhere in the code. Address the slight impedance mismatch by having some functions re-call themselves with flipped arguments when the branch order is reversed. Note that setup_rename_conflict_info() has one asymmetry in it, in setting dst_entry1->processed=0 but not doing similarly for dst_entry2->processed. When dealing with rename/rename and similar conflicts, we do not want the processing to happen twice, so the desire to only set one of the entries to unprocessed is intentional. So, while this change modifies which branch's entry will be marked as unprocessed, that dovetails nicely with putting HEAD first so that we get the index stage entries and conflict markers in the right order. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-recursive.c')
-rw-r--r--merge-recursive.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/merge-recursive.c b/merge-recursive.c
index 8a47e54e2..73b571038 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -228,7 +228,26 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
struct stage_data *src_entry1,
struct stage_data *src_entry2)
{
- struct rename_conflict_info *ci = xcalloc(1, sizeof(struct rename_conflict_info));
+ struct rename_conflict_info *ci;
+
+ /*
+ * When we have two renames involved, it's easiest to get the
+ * correct things into stage 2 and 3, and to make sure that the
+ * content merge puts HEAD before the other branch if we just
+ * ensure that branch1 == o->branch1. So, simply flip arguments
+ * around if we don't have that.
+ */
+ if (dst_entry2 && branch1 != o->branch1) {
+ setup_rename_conflict_info(rename_type,
+ pair2, pair1,
+ branch2, branch1,
+ dst_entry2, dst_entry1,
+ o,
+ src_entry2, src_entry1);
+ return;
+ }
+
+ ci = xcalloc(1, sizeof(struct rename_conflict_info));
ci->rename_type = rename_type;
ci->pair1 = pair1;
ci->branch1 = branch1;
@@ -1283,6 +1302,17 @@ static int merge_mode_and_contents(struct merge_options *o,
const char *branch2,
struct merge_file_info *result)
{
+ if (o->branch1 != branch1) {
+ /*
+ * It's weird getting a reverse merge with HEAD on the bottom
+ * side of the conflict markers and the other branch on the
+ * top. Fix that.
+ */
+ return merge_mode_and_contents(o, one, b, a,
+ filename,
+ branch2, branch1, result);
+ }
+
result->merge = 0;
result->clean = 1;