[PATCH] merge: extract _resolvetrivial() function

Martin von Zweigbergk martinvonz at google.com
Wed Dec 10 21:18:27 UTC 2014


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1417643428 28800
#      Wed Dec 03 13:50:28 2014 -0800
# Node ID 9b8dc07b08a2721d1db6f218bee06880a40d168d
# Parent  07fcb956212223676b35055d39dddac88ca990b6
merge: extract _resolvetrivial() function

We would eventually like to move the resolution of modify/delete and
delete/modify conflicts to the resolve phase. However, we don't want
to move the checks for identical content that were added in
902554884335 (merge: before cd/dc prompt, check that changed side
really changed, 2014-12-01). Let's instead move these out to a new
_resolvetrivial() function that processes the actions from
manifestmerge() and replaces any false cd/dc conflicts. The function
will also provide a natural place for us to later add code for
resolving false 'm' conflicts.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -537,6 +537,30 @@
 
     return actions, diverge, renamedelete
 
+def _resolvetrivial(repo, wctx, mctx, ancestor, actions):
+    """Resolves false conflicts where the nodeid changed but the content
+       remained the same."""
+
+    cdactions = []
+    for action in actions['cd']:
+        f = action[0]
+        if f in ancestor and not wctx[f].cmp(ancestor[f]):
+            # local did change but ended up with same content
+            actions['r'].append((f, None, "prompt same"))
+        else:
+            cdactions.append(action)
+    actions['cd'] = cdactions
+
+    dcactions = []
+    for action in actions['dc']:
+        f = action[0]
+        if f in ancestor and not mctx[f].cmp(ancestor[f]):
+            # remote did change but ended up with same content
+            pass # don't get = keep local deleted
+        else:
+            dcactions.append(action)
+    actions['dc'] = dcactions
+
 def calculateupdates(repo, wctx, mctx, ancestors, branchmerge, force, partial,
                      acceptremote, followcopies):
     "Calculate the actions needed to merge mctx into wctx using ancestors"
@@ -614,12 +638,11 @@
             continue
         repo.ui.note(_('end of auction\n\n'))
 
+    _resolvetrivial(repo, wctx, mctx, ancestors[0], actions)
+
     # Prompt and create actions. TODO: Move this towards resolve phase.
     for f, args, msg in sorted(actions['cd']):
-        if f in ancestors[0] and not wctx[f].cmp(ancestors[0][f]):
-            # local did change but ended up with same content
-            actions['r'].append((f, None, "prompt same"))
-        elif repo.ui.promptchoice(
+        if repo.ui.promptchoice(
             _("local changed %s which remote deleted\n"
               "use (c)hanged version or (d)elete?"
               "$$ &Changed $$ &Delete") % f, 0):
@@ -630,10 +653,7 @@
 
     for f, args, msg in sorted(actions['dc']):
         flags, = args
-        if f in ancestors[0] and not mctx[f].cmp(ancestors[0][f]):
-            # remote did change but ended up with same content
-            pass # don't get = keep local deleted
-        elif repo.ui.promptchoice(
+        if repo.ui.promptchoice(
             _("remote changed %s which local deleted\n"
               "use (c)hanged version or leave (d)eleted?"
               "$$ &Changed $$ &Deleted") % f, 0) == 0:


More information about the Mercurial-devel mailing list