changeset 23396:6a254a2dd37c

merge: separate out "both created" cases When 'f' is not in 'ma', 'a' will be 'nullid' and all the if/elif conditions that check whether some one nodeid is equal to 'a' will fail, and the else-clause will instead apply. We can make that more explicit by creating a separate 'm' action for the case where 'a' is 'nullid'. While it does mean copying some code, perhaps it makes it a little clearer which codepaths are possible, and which cases the "Note:" in the code refers to. It also lets us make the debug action messages a little more specific.
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 24 Nov 2014 16:16:34 -0800
parents d9ebb475eede
children c7c95838be9a
files mercurial/merge.py tests/test-rename-merge2.t tests/test-up-local-change.t
diffstat 3 files changed, 20 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Mon Nov 24 16:11:22 2014 -0800
+++ b/mercurial/merge.py	Mon Nov 24 16:16:34 2014 -0800
@@ -415,14 +415,15 @@
         if partial and not partial(f):
             continue
         if n1 and n2:
-            if True:
-                fa = f
-                a = ma.get(f, nullid)
-                if a == nullid:
-                    fa = copy.get(f, f)
-                    # Note: f as default is wrong - we can't really make a 3-way
-                    # merge without an ancestor file.
-                fla = ma.flags(fa)
+            if f not in ma:
+                # Note: f as ancestor is wrong - we can't really make a 3-way
+                # merge without an ancestor file.
+                fa = copy.get(f, f)
+                actions['m'].append((f, (f, f, fa, False, pa.node()),
+                               "both created"))
+            else:
+                a = ma[f]
+                fla = ma.flags(f)
                 nol = 'l' not in fl1 + fl2 + fla
                 if n2 == a and fl2 == fla:
                     actions['k'].append((f, (), "keep")) # remote unchanged
@@ -436,7 +437,7 @@
                 elif nol and n1 == a: # local only changed 'x'
                     actions['g'].append((f, (fl1,), "remote is newer"))
                 else: # both changed something
-                    actions['m'].append((f, (f, f, fa, False, pa.node()),
+                    actions['m'].append((f, (f, f, f, False, pa.node()),
                                    "versions differ"))
         elif f in copied: # files we'll deal with on m2 side
             pass
--- a/tests/test-rename-merge2.t	Mon Nov 24 16:11:22 2014 -0800
+++ b/tests/test-rename-merge2.t	Mon Nov 24 16:16:34 2014 -0800
@@ -343,7 +343,7 @@
    ancestor: 924404dff337, local: 62e7bf090eba+, remote: 49b6d8032493
    preserving b for resolve of b
    preserving rev for resolve of rev
-   b: versions differ -> m
+   b: both created -> m
   updating: b 1/2 files (50.00%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -413,7 +413,7 @@
    ancestor: 924404dff337, local: 86a2aa42fc76+, remote: af30c7647fc7
    preserving b for resolve of b
    preserving rev for resolve of rev
-   b: versions differ -> m
+   b: both created -> m
   updating: b 1/2 files (50.00%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -446,7 +446,7 @@
    a: other deleted -> r
   removing a
   updating: a 1/3 files (33.33%)
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/3 files (66.67%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -478,7 +478,7 @@
    a: remote is newer -> g
   getting a
   updating: a 1/3 files (33.33%)
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/3 files (66.67%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -511,7 +511,7 @@
    a: other deleted -> r
   removing a
   updating: a 1/3 files (33.33%)
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/3 files (66.67%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -543,7 +543,7 @@
    a: remote is newer -> g
   getting a
   updating: a 1/3 files (33.33%)
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/3 files (66.67%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -574,7 +574,7 @@
    preserving b for resolve of b
    preserving rev for resolve of rev
    a: keep -> k
-   b: versions differ -> m
+   b: both created -> m
   updating: b 1/2 files (50.00%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -609,7 +609,7 @@
    a: prompt recreating -> g
   getting a
   updating: a 1/3 files (33.33%)
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/3 files (66.67%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
@@ -643,7 +643,7 @@
    preserving rev for resolve of rev
    a: prompt keep -> a
   updating: a 1/3 files (33.33%)
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/3 files (66.67%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b
--- a/tests/test-up-local-change.t	Mon Nov 24 16:11:22 2014 -0800
+++ b/tests/test-up-local-change.t	Mon Nov 24 16:16:34 2014 -0800
@@ -188,7 +188,7 @@
   picked tool 'true' for a (binary False symlink False)
   merging a
   my a@1e71731e6fbb+ other a@83c51d0caff4 ancestor a@c19d34741b0a
-   b: versions differ -> m
+   b: both created -> m
   updating: b 2/2 files (100.00%)
   picked tool 'true' for b (binary False symlink False)
   merging b