Patchwork [5,of,6] merge: break out "both renamed a -> b" case

login
register
mail settings
Submitter Martin von Zweigbergk
Date Nov. 25, 2014, 5:22 a.m.
Message ID <9a17f0a1c28705f0d7fd.1416892971@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/6849/
State Accepted
Commit c7c95838be9adc11a2697d71ea011347adc0212e
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 1416876156 28800
#      Mon Nov 24 16:42:36 2014 -0800
# Node ID 9a17f0a1c28705f0d7fdf7732d94f27087892dad
# Parent  0b4e074c8fbf92a2dff503ad8bb8ae581506ee84
merge: break out "both renamed a -> b" case

We can further limit the scope of the 2-way merge case by breaking out
the case where the file was not created from scratch on both sides but
rather renamed in the same way (and is therefore a 3-way merge). This
involves copying some code, but it makes it clearer which case the
"Note:" in the code refers to.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -416,11 +416,15 @@ 
             continue
         if n1 and n2:
             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"))
+                fa = copy.get(f, None)
+                if fa is not None:
+                    actions['m'].append((f, (f, f, fa, False, pa.node()),
+                                   "both renamed from " + fa))
+                else:
+                    # Note: f as ancestor is wrong - we can't really make a
+                    # 3-way merge without an ancestor file.
+                    actions['m'].append((f, (f, f, f, False, pa.node()),
+                                   "both created"))
             else:
                 a = ma[f]
                 fla = ma.flags(f)
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: both created -> m
+   b: both renamed from a -> m
   updating: b 1/2 files (50.00%)
   picked tool 'python ../merge' for b (binary False symlink False)
   merging b