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

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Aug. 24, 2014, 11:06 p.m.
Message ID <44ecb51c857da4cbfddc.1408921599@Iris>
Download mbox | patch
Permalink /patch/5580/
State Superseded
Commit ed12abab068eccec965d8ccf3a78a42b20c78762
Headers show

Comments

Jordi Gutiérrez Hermoso - Aug. 24, 2014, 11:06 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1408921065 14400
#      Sun Aug 24 18:57:45 2014 -0400
# Node ID 44ecb51c857da4cbfddcc8c1220747a477a96ac2
# Parent  172abbcbcf6ffcd1d17d8ca8100230adb3db27b7
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
@@ -82,7 +82,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
@@ -111,18 +112,25 @@  class Merge3Text(object):
                 for i in range(t[1], t[2]):
                     yield self.b[i]
             elif what == 'conflict':
-                self.conflicts = True
-                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]
-                yield mid_marker + newline
-                for i in range(t[5], t[6]):
-                    yield self.b[i]
-                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
+                    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]
+                    yield mid_marker + newline
+                    for i in range(t[5], t[6]):
+                        yield self.b[i]
+                    yield end_marker + newline
             else:
                 raise ValueError(what)
 
@@ -373,7 +381,7 @@  def simplemerge(ui, local, base, other, 
         out = sys.stdout
 
     m3 = Merge3Text(basetext, localtext, othertext)
-    extrakwargs = {}
+    extrakwargs = {"localorother": opts.get("localorother", None)}
     if name_base is not None:
         extrakwargs['base_marker'] = '|||||||'
         extrakwargs['name_base'] = name_base