D11978: simplemerge: split out function for rendering :merge3 conflict markers
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Wed Jan 12 06:56:27 UTC 2022
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
The results in some duplicate, but the code is very straight-forward
and I think it's worth it to have each conflict marker style in a
separate function.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D11978
AFFECTED FILES
mercurial/simplemerge.py
CHANGE DETAILS
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -354,11 +354,9 @@
m3,
name_a=None,
name_b=None,
- name_base=None,
start_marker=b'<<<<<<<',
mid_marker=b'=======',
end_marker=b'>>>>>>>',
- base_marker=None,
minimize=False,
):
"""Return merge in cvs-like form."""
@@ -368,8 +366,6 @@
start_marker = start_marker + b' ' + name_a
if name_b and end_marker:
end_marker = end_marker + b' ' + name_b
- if name_base and base_marker:
- base_marker = base_marker + b' ' + name_base
merge_groups = m3.merge_groups()
if minimize:
merge_groups = m3.minimize(merge_groups)
@@ -381,9 +377,6 @@
if start_marker is not None:
lines.append(start_marker + newline)
lines.extend(a_lines)
- if base_marker is not None:
- lines.append(base_marker + newline)
- lines.extend(base_lines)
if mid_marker is not None:
lines.append(mid_marker + newline)
lines.extend(b_lines)
@@ -394,7 +387,29 @@
return lines, conflicts
+def render_merge3(m3, name_a, name_b, name_base):
+ """Render conflicts as 3-way conflict markers."""
+ newline = _detect_newline(m3)
+ conflicts = False
+ lines = []
+ for what, group_lines in m3.merge_groups():
+ if what == b'conflict':
+ base_lines, a_lines, b_lines = group_lines
+ conflicts = True
+ lines.append(b'<<<<<<< ' + name_a + newline)
+ lines.extend(a_lines)
+ lines.append(b'||||||| ' + name_base + newline)
+ lines.extend(base_lines)
+ lines.append(b'=======' + newline)
+ lines.extend(b_lines)
+ lines.append(b'>>>>>>> ' + name_b + newline)
+ else:
+ lines.extend(group_lines)
+ return lines, conflicts
+
+
def render_mergediff(m3, name_a, name_b, name_base):
+ """Render conflicts as conflict markers with one snapshot and one diff."""
newline = _detect_newline(m3)
lines = []
conflicts = False
@@ -504,14 +519,12 @@
name_a, name_b, name_base = _picklabels(opts.get('label', []))
if mode == b'mergediff':
lines, conflicts = render_mergediff(m3, name_a, name_b, name_base)
+ elif mode == b'merge3':
+ lines, conflicts = render_merge3(m3, name_a, name_b, name_base)
else:
extrakwargs = {
'minimize': True,
}
- if mode == b'merge3':
- extrakwargs['base_marker'] = b'|||||||'
- extrakwargs['name_base'] = name_base
- extrakwargs['minimize'] = False
lines, conflicts = render_markers(
m3, name_a=name_a, name_b=name_b, **extrakwargs
)
To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list