Patchwork [1,of,2] simplemerge: enable option to resolve conflicts one way

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Sept. 10, 2015, 1:46 p.m.
Message ID <b39d3a8d66dfb964ceff.1441892782@Iris>
Download mbox | patch
Permalink /patch/10461/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - Sept. 10, 2015, 1:46 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1439383981 14400
#      Wed Aug 12 08:53:01 2015 -0400
# Node ID b39d3a8d66dfb964ceffda0fecdb9f7fd47449ef
# Parent  ea489d94e1dc1fc3dc1dcbef1c86c18c49605ed1
simplemerge: enable option to resolve conflicts one way

With this change, the simplemerge algorithm grows an option to only
return the local or the other hunk in a conflicting region.

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -90,7 +90,8 @@  class Merge3Text(object):
                     start_marker='<<<<<<<',
                     mid_marker='=======',
                     end_marker='>>>>>>>',
-                    base_marker=None):
+                    base_marker=None,
+                    localorother=None):
         """Return merge in cvs-like form.
         """
         self.conflicts = False
@@ -119,21 +120,28 @@  class Merge3Text(object):
                 for i in range(t[1], t[2]):
                     yield self.b[i]
             elif what == 'conflict':
-                self.conflicts = True
-                if start_marker is not None:
-                    yield start_marker + newline
-                for i in range(t[3], t[4]):
-                    yield self.a[i]
-                if base_marker is not None:
-                    yield base_marker + newline
-                    for i in range(t[1], t[2]):
-                        yield self.base[i]
-                if mid_marker is not None:
-                    yield mid_marker + newline
-                for i in range(t[5], t[6]):
-                    yield self.b[i]
-                if end_marker is not None:
-                    yield end_marker + newline
+                if localorother == 'local':
+                    for i in range(t[3], t[4]):
+                        yield self.a[i]
+                elif localorother == 'other':
+                    for i in range(t[5], t[6]):
+                        yield self.b[i]
+                else:
+                    self.conflicts = True
+                    if start_marker is not None:
+                        yield start_marker + newline
+                    for i in range(t[3], t[4]):
+                        yield self.a[i]
+                    if base_marker is not None:
+                        yield base_marker + newline
+                        for i in range(t[1], t[2]):
+                            yield self.base[i]
+                    if mid_marker is not None:
+                        yield mid_marker + newline
+                    for i in range(t[5], t[6]):
+                        yield self.b[i]
+                    if end_marker is not None:
+                        yield end_marker + newline
             else:
                 raise ValueError(what)
 
@@ -390,7 +398,7 @@  def simplemerge(ui, local, base, other, 
         out = sys.stdout
 
     m3 = Merge3Text(basetext, localtext, othertext)
-    extrakwargs = {}
+    extrakwargs = {"localorother": opts.get("localorother", None)}
     if mode == 'union':
         extrakwargs['start_marker'] = None
         extrakwargs['mid_marker'] = None