Patchwork [4,of,6] merge: separate out "both created" cases

login
register
mail settings
Submitter Martin von Zweigbergk
Date Nov. 25, 2014, 5:22 a.m.
Message ID <0b4e074c8fbf92a2dff5.1416892970@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/6846/
State Accepted
Commit 6a254a2dd37ca786e5074c2940bff7d71c0f164f
Delegated to: Pierre-Yves David
Headers show

Comments

Martin von Zweigbergk - Nov. 25, 2014, 5:22 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1416874594 28800
#      Mon Nov 24 16:16:34 2014 -0800
# Node ID 0b4e074c8fbf92a2dff503ad8bb8ae581506ee84
# Parent  5686367c7f2b06b954bd8a5bb5504d863fd6fd71
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.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -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
diff --git a/tests/test-rename-merge2.t b/tests/test-rename-merge2.t
--- a/tests/test-rename-merge2.t
+++ b/tests/test-rename-merge2.t
@@ -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
diff --git a/tests/test-up-local-change.t b/tests/test-up-local-change.t
--- a/tests/test-up-local-change.t
+++ b/tests/test-up-local-change.t
@@ -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