[Updated] D11979: simplemerge: simplify and rename `render_markers()`
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon Jan 17 13:17:26 UTC 2022
Closed by commit rHG03760d1ec0cc: simplemerge: simplify and rename `render_markers()` (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11979?vs=31634&id=31673
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11979/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11979
AFFECTED FILES
mercurial/debugcommands.py
mercurial/simplemerge.py
tests/test-simplemerge.py
CHANGE DETAILS
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:
To: martinvonz, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220117/74e4466a/attachment-0002.html>
More information about the Mercurial-patches
mailing list