Mercurial > hg
diff mercurial/simplemerge.py @ 48561:69e76b2aad3d
simplemerge: split out function for rendering :merge3 conflict markers
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.
Differential Revision: https://phab.mercurial-scm.org/D11978
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 11 Jan 2022 16:23:10 -0800 |
parents | 6ad70879d2bd |
children | 12ac4401ff7d |
line wrap: on
line diff
--- a/mercurial/simplemerge.py Fri Jan 07 23:29:19 2022 -0800 +++ b/mercurial/simplemerge.py Tue Jan 11 16:23:10 2022 -0800 @@ -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 )