changeset 48590:12ac4401ff7d

simplemerge: simplify and rename `render_markers()` `render_markers()` now always renders minimized 2-way markers, so let's simplify and rename it accordingly. Differential Revision: https://phab.mercurial-scm.org/D11979
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 11 Jan 2022 21:56:27 -0800
parents 69e76b2aad3d
children ad0c6bf6f02e
files mercurial/debugcommands.py mercurial/simplemerge.py tests/test-simplemerge.py
diffstat 3 files changed, 20 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Tue Jan 11 16:23:10 2022 -0800
+++ b/mercurial/debugcommands.py	Tue Jan 11 21:56:27 2022 -0800
@@ -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:
--- a/mercurial/simplemerge.py	Tue Jan 11 16:23:10 2022 -0800
+++ b/mercurial/simplemerge.py	Tue Jan 11 21:56:27 2022 -0800
@@ -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'):
--- a/tests/test-simplemerge.py	Tue Jan 11 16:23:10 2022 -0800
+++ b/tests/test-simplemerge.py	Tue Jan 11 21:56:27 2022 -0800
@@ -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),