Patchwork D11979: simplemerge: simplify and rename `render_markers()`

login
register
mail settings
Submitter phabricator
Date Jan. 12, 2022, 6:57 a.m.
Message ID <differential-rev-PHID-DREV-amopklkvs4klnkqvv5aj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50307/
State New
Headers show

Comments

phabricator - Jan. 12, 2022, 6:57 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `render_markers()` now always renders minimized 2-way markers, so
  let's simplify and rename it accordingly.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11979

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/simplemerge.py
  tests/test-simplemerge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-simplemerge.py b/tests/test-simplemerge.py
--- a/tests/test-simplemerge.py
+++ b/tests/test-simplemerge.py
@@ -180,7 +180,7 @@ 
         self.assertEqual(list(m3.merge_regions()), [(b'a', 0, 2)])
 
         self.assertEqual(
-            simplemerge.render_markers(m3), ([b'aaa', b'bbb'], False)
+            simplemerge.render_minimized(m3), ([b'aaa', b'bbb'], False)
         )
 
     def test_no_conflicts(self):
@@ -207,7 +207,7 @@ 
         )
 
         self.assertEqual(
-            b''.join(simplemerge.render_markers(m3)[0]), b'aaa\nbbb\n222\n'
+            b''.join(simplemerge.render_minimized(m3)[0]), b'aaa\nbbb\n222\n'
         )
 
     def test_append_b(self):
@@ -218,7 +218,7 @@ 
         )
 
         self.assertEqual(
-            b''.join(simplemerge.render_markers(m3)[0]), b'aaa\nbbb\n222\n'
+            b''.join(simplemerge.render_minimized(m3)[0]), b'aaa\nbbb\n222\n'
         )
 
     def test_append_agreement(self):
@@ -229,7 +229,7 @@ 
         )
 
         self.assertEqual(
-            b''.join(simplemerge.render_markers(m3)[0]), b'aaa\nbbb\n222\n'
+            b''.join(simplemerge.render_minimized(m3)[0]), b'aaa\nbbb\n222\n'
         )
 
     def test_append_clash(self):
@@ -239,7 +239,7 @@ 
             [b'aaa\n', b'bbb\n', b'333\n'],
         )
 
-        ml, conflicts = simplemerge.render_markers(
+        ml, conflicts = simplemerge.render_minimized(
             m3,
             name_a=b'a',
             name_b=b'b',
@@ -259,7 +259,7 @@ 
             [b'aaa\n', b'222\n', b'bbb\n'],
         )
 
-        ml, conflicts = simplemerge.render_markers(
+        ml, conflicts = simplemerge.render_minimized(
             m3,
             name_a=b'a',
             name_b=b'b',
@@ -300,7 +300,7 @@ 
             ],
         )
 
-        ml, conflicts = simplemerge.render_markers(
+        ml, conflicts = simplemerge.render_minimized(
             m3,
             name_a=b'a',
             name_b=b'b',
@@ -349,7 +349,7 @@ 
     def test_merge_poem(self):
         """Test case from diff3 manual"""
         m3 = Merge3(TZU, LAO, TAO)
-        ml, conflicts = simplemerge.render_markers(m3, b'LAO', b'TAO')
+        ml, conflicts = simplemerge.render_minimized(m3, b'LAO', b'TAO')
         self.log(b'merge result:')
         self.log(b''.join(ml))
         self.assertEqual(ml, MERGED_RESULT)
@@ -367,7 +367,7 @@ 
             other_text.splitlines(True),
             this_text.splitlines(True),
         )
-        m_lines, conflicts = simplemerge.render_markers(m3, b'OTHER', b'THIS')
+        m_lines, conflicts = simplemerge.render_minimized(m3, b'OTHER', b'THIS')
         self.assertEqual(
             b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
             b'>>>>>>> THIS\r\n'.splitlines(True),
@@ -383,7 +383,7 @@ 
             other_text.splitlines(True),
             this_text.splitlines(True),
         )
-        m_lines, conflicts = simplemerge.render_markers(m3, b'OTHER', b'THIS')
+        m_lines, conflicts = simplemerge.render_minimized(m3, b'OTHER', b'THIS')
         self.assertEqual(
             b'<<<<<<< OTHER\rc\r=======\rb\r'
             b'>>>>>>> THIS\r'.splitlines(True),
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -350,38 +350,33 @@ 
     return b'\n'
 
 
-def render_markers(
+def render_minimized(
     m3,
     name_a=None,
     name_b=None,
     start_marker=b'<<<<<<<',
     mid_marker=b'=======',
     end_marker=b'>>>>>>>',
-    minimize=False,
 ):
     """Return merge in cvs-like form."""
     newline = _detect_newline(m3)
     conflicts = False
-    if name_a and start_marker:
+    if name_a:
         start_marker = start_marker + b' ' + name_a
-    if name_b and end_marker:
+    if name_b:
         end_marker = end_marker + b' ' + name_b
     merge_groups = m3.merge_groups()
-    if minimize:
-        merge_groups = m3.minimize(merge_groups)
+    merge_groups = m3.minimize(merge_groups)
     lines = []
     for what, group_lines in merge_groups:
         if what == b'conflict':
             base_lines, a_lines, b_lines = group_lines
             conflicts = True
-            if start_marker is not None:
-                lines.append(start_marker + newline)
+            lines.append(start_marker + newline)
             lines.extend(a_lines)
-            if mid_marker is not None:
-                lines.append(mid_marker + newline)
+            lines.append(mid_marker + newline)
             lines.extend(b_lines)
-            if end_marker is not None:
-                lines.append(end_marker + newline)
+            lines.append(end_marker + newline)
         else:
             lines.extend(group_lines)
     return lines, conflicts
@@ -522,12 +517,7 @@ 
         elif mode == b'merge3':
             lines, conflicts = render_merge3(m3, name_a, name_b, name_base)
         else:
-            extrakwargs = {
-                'minimize': True,
-            }
-            lines, conflicts = render_markers(
-                m3, name_a=name_a, name_b=name_b, **extrakwargs
-            )
+            lines, conflicts = render_minimized(m3, name_a, name_b)
 
     mergedtext = b''.join(lines)
     if opts.get('print'):
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -273,7 +273,8 @@ 
                         ]
                         m3 = simplemerge.Merge3Text(base, local, other)
                         ml = [
-                            l.strip() for l in simplemerge.render_markers(m3)[0]
+                            l.strip()
+                            for l in simplemerge.render_minimized(m3)[0]
                         ]
                         ml.append(b"")
                     elif at > 0: