From patchwork Wed Sep 23 08:18:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [6, of, 9] merge: store commitinfo if mergetool resolved a dc or cd conflict From: Pulkit Goyal <7895pulkit@gmail.com> X-Patchwork-Id: 47251 Message-Id: <30332428d8b023305374.1600849101@workspace> To: mercurial-devel@mercurial-scm.org Date: Wed, 23 Sep 2020 13:48:21 +0530 # HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1599120846 -19800 # Thu Sep 03 13:44:06 2020 +0530 # Node ID 30332428d8b0233053742be0c27bcb3e6499ed15 # Parent 62404f1a66ec45ca819d411746138894dcab6e91 # EXP-Topic merge-newnode merge: store commitinfo if mergetool resolved a dc or cd conflict delete-changed or changed-delete conflicts can be resolved by mergetool, either if some tool is passed and using or by user choose something on prompt. 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 diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -1608,6 +1608,27 @@ def applyupdates( if not complete: numupdates += 1 tocomplete.append((f, args, msg)) + else: + action = mresult.getfile(f)[0] + if action in ( + mergestatemod.ACTION_DELETED_CHANGED, + mergestatemod.ACTION_CHANGED_DELETED, + ): + # the merge was conflicting and either the mergetool + # choosed by the user or the user themselves on the prompt + # made a choice. + # If the changed file was kept, at commit we end up using + # the same filelog. This is not completely correct behavior + # as the new file post merge also represents that a + # conflicting change-delete merge was resolved in it's + # favor. Hence we will like to create a new filenode for + # that. Let's store this in mergestate extras + repo.ui.debug( + b"file %s had %s conflicts and mergetool resolved it, storing info in commitinfo\n" + % (f, action) + ) + + ms.addcommitinfo(f, {b'MERGE_REMOVAL_CANDIDATE': b'yes'}) # merge for f, args, msg in tocomplete: 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 "") @@ -768,11 +788,13 @@ Non-interactive linear update 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 --- file1 --- 1 @@ -807,11 +829,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 --- file1 --- 1 @@ -844,11 +868,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 *** file1 does not exist --- file2 --- @@ -883,11 +909,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 --- file1 --- 1 @@ -930,11 +958,13 @@ Force prompts with no 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 --- file1 --- 1 @@ -978,11 +1008,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 --- file1 --- 1 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 @@ -534,6 +534,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" @@ -556,6 +557,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 @@ -578,6 +580,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" @@ -607,6 +610,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