Patchwork [6,of,9,V2] merge: store commitinfo if these is a dc or cd conflict

login
register
mail settings
Submitter Pulkit Goyal
Date Sept. 25, 2020, 9:16 a.m.
Message ID <5a6f126f9a019e5a5c6a.1601025415@workspace>
Download mbox | patch
Permalink /patch/47282/
State Accepted
Headers show

Comments

Pulkit Goyal - Sept. 25, 2020, 9:16 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1599120846 -19800
#      Thu Sep 03 13:44:06 2020 +0530
# Node ID 5a6f126f9a019e5a5c6af1a245275f4010530c85
# Parent  e85a8500a0ba6cec21b84ff13c4558c1bcc64e2d
# EXP-Topic merge-newnode
merge: store commitinfo if these is a dc or cd conflict

delete-changed or changed-delete conflicts can either be resolved by mergetool,
if some tool is passed and using or by user choose something on prompt or user
doing some `hg revert` after choosing the file to remain conflicted.

If the user decides to keep the changed side, on commit we just reuse the parent
filenode. This is mostly fine unless we are in a distributed environment and
people are doing criss-cross merges.

Since, we don't have recursive merges or any other way of describing the end
result of the merge was an explicit choice and it should be differentiated from
it's ancestors, merge algo during criss-cross merges fails to take in account
the explicit choice made by user and end up with a what-can-be-said-wrong-merge.

The solution which we are trying to fix this is by creating a filenode on commit
instead of reusing the parent filenode. This helps differentiate between
pre-merged filenode and post-merge filenode and kind of tells about the choice
user made.

To implement creating new filenode functionality, we store info about these
files in mergestate so that we can read them on commit and force create a new
filenode.

Differential Revision: https://phab.mercurial-scm.org/D8988

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -909,6 +909,10 @@  def manifestmerge(
                             (f, None, f, False, pa.node()),
                             b'prompt changed/deleted',
                         )
+                        if branchmerge:
+                            mresult.addcommitinfo(
+                                f, 'MERGE_REMOVAL_CANDIDATE', 'yes'
+                            )
                 elif n1 == addednodeid:
                     # This file was locally added. We should forget it instead of
                     # deleting it.
@@ -1018,6 +1022,10 @@  def manifestmerge(
                         (None, f, f, False, pa.node()),
                         b'prompt deleted/changed',
                     )
+                    if branchmerge:
+                        mresult.addcommitinfo(
+                            f, 'MERGE_REMOVAL_CANDIDATE', 'yes'
+                        )
             else:
                 mresult.addfile(
                     f,
diff --git a/tests/test-merge-changedelete.t b/tests/test-merge-changedelete.t
--- a/tests/test-merge-changedelete.t
+++ b/tests/test-merge-changedelete.t
@@ -82,11 +82,13 @@  Non-interactive merge:
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "u")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -147,11 +149,13 @@  Interactive merge:
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "r")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -225,11 +229,13 @@  Interactive merge with bad input:
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "r")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -287,11 +293,13 @@  Interactive merge with not enough input:
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "u")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -336,11 +344,13 @@  Choose local versions of files
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "r")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "r")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -381,11 +391,13 @@  Choose other versions of files
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "r")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "r")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -427,11 +439,13 @@  Fail
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "u")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -484,11 +498,13 @@  Force prompts with no input (should be s
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "u")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -543,11 +559,13 @@  Force prompts
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "u")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
@@ -599,11 +617,13 @@  Choose to merge all files
     local path: file1 (hash 60b27f004e454aca81b0480209cce5081ec52390, flags "")
     ancestor path: file1 (node b8e02f6433738021a065f94175c7cd23db5f05be)
     other path: file1 (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file2 (state "u")
     local path: file2 (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: file2 (node 5d9299349fc01ddd25d0070d149b124d8f10411e)
     other path: file2 (node e7c1328648519852e723de86c0c0525acd779257)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = ab57bf49aa276a22d35a473592d4c34b5abc3eff
   file: file3 (state "u")
     local path: file3 (hash d5b0a58bc47161b1b8a831084b366f757c4f0b11, flags "")
diff --git a/tests/test-merge-criss-cross.t b/tests/test-merge-criss-cross.t
--- a/tests/test-merge-criss-cross.t
+++ b/tests/test-merge-criss-cross.t
@@ -538,6 +538,7 @@  Do all the merge combination (from the deleted or the update side × keeping and deleting the file
     local path: the-file (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: the-file (node 4b69178b9bdae28b651393b46e631427a72f217a)
     other path: the-file (node 59e363a07dc876278f0e41756236f30213b6b460)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = 955800955977bd6c103836ee3e437276e940a589
   extra: other-file (filenode-source = other)
   $ hg ci -m "merge-deleting-the-file-from-deleted"
@@ -560,6 +561,7 @@  Do all the merge combination (from the deleted or the update side × keeping and deleting the file
     local path: the-file (hash 6d2e02da5a9fe0691363dc6b573845fa271eaa35, flags "")
     ancestor path: the-file (node 4b69178b9bdae28b651393b46e631427a72f217a)
     other path: the-file (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = 955800955977bd6c103836ee3e437276e940a589
   $ hg ci -m "merge-deleting-the-file-from-updated"
   created new head
@@ -582,6 +584,7 @@  Do all the merge combination (from the deleted or the update side × keeping and deleting the file
     local path: the-file (hash 0000000000000000000000000000000000000000, flags "")
     ancestor path: the-file (node 4b69178b9bdae28b651393b46e631427a72f217a)
     other path: the-file (node 59e363a07dc876278f0e41756236f30213b6b460)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = 955800955977bd6c103836ee3e437276e940a589
   extra: other-file (filenode-source = other)
   $ hg ci -m "merge-keeping-the-file-from-deleted"
@@ -611,6 +614,7 @@  in consideration.
     local path: the-file (hash 6d2e02da5a9fe0691363dc6b573845fa271eaa35, flags "")
     ancestor path: the-file (node 4b69178b9bdae28b651393b46e631427a72f217a)
     other path: the-file (node 0000000000000000000000000000000000000000)
+    extra: MERGE_REMOVAL_CANDIDATE = yes
     extra: ancestorlinknode = 955800955977bd6c103836ee3e437276e940a589
   $ hg ci -m "merge-keeping-the-file-from-updated"
   created new head