# HG changeset patch # User Martin von Zweigbergk # Date 2022-01-20 19:06:52 # Node ID 3c8cc987672e05abe7b7b4a69e9da69e18b7cac3 # Parent fd9fe2658cdaf98039b68ccbced38f426c37076e simplemerge: take over formatting of label from `filemerge` The padding we do of conflict labels depends on which conflict marker style is used. For two-way conflict markers (the default), the length of the base label shouldn't matter. It does before this patch, however. This patch moves the formatting from `filemerge` to `simplemerge`. The latter knows which conflict marker style to use, so it can easily decide about the padding. This change will allow us to use more descriptive "base" labels without causing illogical padding in 2-way markers. I'll do that next. One wrinkle is that we pass the same labels to external merge tools. I decided to change that in this patch to be simpler: no padding, and no ellipsis to fit within 80 columns. My reasoning is that the typical external, 3-or-4-panel merge tool doesn't show the labels on top of each others, so the padding doesn't make sense there. The ellipsis is probably not necessary because the external tools probably have their own way of dealing with long labels. Also, we limit them to "80 - 8" to fit the "<<<<<<< " before, which is almost definitely not what an external tool would put there. Differential Revision: https://phab.mercurial-scm.org/D12019 diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -40,7 +40,6 @@ from . import ( from .utils import ( procutil, - stringutil, ) @@ -724,6 +723,13 @@ def _xmerge(repo, mynode, local, other, ) as temppaths: basepath, otherpath, localoutputpath = temppaths outpath = b"" + + def format_label(input): + if input.label_detail: + return b'%s: %s' % (input.label, input.label_detail) + else: + return input.label + env = { b'HG_FILE': fcd.path(), b'HG_MY_NODE': short(mynode), @@ -732,9 +738,9 @@ def _xmerge(repo, mynode, local, other, b'HG_MY_ISLINK': b'l' in fcd.flags(), b'HG_OTHER_ISLINK': b'l' in fco.flags(), b'HG_BASE_ISLINK': b'l' in fca.flags(), - b'HG_MY_LABEL': local.label, - b'HG_OTHER_LABEL': other.label, - b'HG_BASE_LABEL': base.label, + b'HG_MY_LABEL': format_label(local), + b'HG_OTHER_LABEL': format_label(other), + b'HG_BASE_LABEL': format_label(base), } ui = repo.ui @@ -747,9 +753,9 @@ def _xmerge(repo, mynode, local, other, b'base': basepath, b'other': otherpath, b'output': outpath, - b'labellocal': local.label, - b'labelother': other.label, - b'labelbase': base.label, + b'labellocal': format_label(local), + b'labelother': format_label(other), + b'labelbase': format_label(base), } args = util.interpolate( br'\$', @@ -801,32 +807,19 @@ def _xmerge(repo, mynode, local, other, return True, r, False -def _populate_label_detail(input, template, pad): - """Applies the given template to the ctx, prefixed by the label. - - Pad is the minimum width of the label prefix, so that multiple markers - can have aligned templated parts. - """ +def _populate_label_detail(input, template): + """Applies the given template to the ctx and stores it in the input.""" ctx = input.fctx.changectx() if ctx.node() is None: ctx = ctx.p1() props = {b'ctx': ctx} templateresult = template.renderdefault(props) - - label = (b'%s:' % input.label).ljust(pad + 1) - mark = b'%s %s' % (label, templateresult) - mark = mark.splitlines()[0] # split for safety - - # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ') - input.label = stringutil.ellipsis(mark, 80 - 8) + input.label_detail = templateresult.splitlines()[0] # split for safety def _populate_label_details(repo, inputs, tool=None): - """Formats the given labels using the conflict marker template. - - Returns a list of formatted labels. - """ + """Populates the label details using the conflict marker template.""" ui = repo.ui template = ui.config(b'command-templates', b'mergemarker') if tool is not None: @@ -837,10 +830,8 @@ def _populate_label_details(repo, inputs ui, template, defaults=templatekw.keywords, resources=tres ) - pad = max(len(input.label) for input in inputs) - for input in inputs: - _populate_label_detail(input, tmpl, pad) + _populate_label_detail(input, tmpl) def partextras(labels): @@ -1111,9 +1102,9 @@ def filemerge(repo, wctx, mynode, orig, return r, False # Reset to basic labels - local.label = labels[0] - other.label = labels[1] - base.label = labels[2] + local.label_detail = None + other.label_detail = None + base.label_detail = None if markerstyle != b'basic': _populate_label_details(repo, [local, other, base], tool=tool) diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py --- a/mercurial/simplemerge.py +++ b/mercurial/simplemerge.py @@ -286,10 +286,20 @@ def _verifytext(text, path, ui, opts): def _format_labels(*inputs): + pad = max(len(input.label) if input.label else 0 for input in inputs) labels = [] for input in inputs: if input.label: - labels.append(input.label) + if input.label_detail: + label = ( + (input.label + b':').ljust(pad + 1) + + b' ' + + input.label_detail + ) + else: + label = input.label + # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ') + labels.append(stringutil.ellipsis(label, 80 - 8)) else: labels.append(None) return labels @@ -468,6 +478,10 @@ def _resolve(m3, sides): class MergeInput(object): fctx = attr.ib() label = attr.ib(default=None) + # If the "detail" part is set, then that is rendered after the label and + # separated by a ':'. The label is padded to make the ':' aligned among all + # merge inputs. + label_detail = attr.ib(default=None) def simplemerge(ui, local, base, other, **opts): diff --git a/relnotes/next b/relnotes/next --- a/relnotes/next +++ b/relnotes/next @@ -18,6 +18,12 @@ The `--no-check` and `--no-merge` now pr The remotefilelog extension now requires an appropiate excludepattern for subrepositories. +The labels passed to merge tools have changed slightly. Merge tools can get +labels passed to them if you include `$labellocal`, `$labelbase`, and/or +`$labelother` in the `merge-tool..args` configuration. These labels +used to have some space-padding, and truncation to fit within 72 columns. Both +the padding and the truncation has been removed. + == Internal API Changes == The following functions have been removed: diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t --- a/tests/test-merge-tools.t +++ b/tests/test-merge-tools.t @@ -1648,7 +1648,7 @@ mergemarkertemplate: merging f arg: "ll:working copy: tooltmpl ef83787e2614" arg: "lo:" - arg: "merge rev: tooltmpl 0185f4e0cf02" + arg: "merge rev: tooltmpl 0185f4e0cf02" arg: "lb:base: */f~base.*" (glob) 0 files updated, 1 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) @@ -1718,7 +1718,7 @@ mergemarkers=detailed; labellocal and la > merge -r 2 merging f labellocal: "working copy: tooltmpl ef83787e2614" - labelother: "merge rev: tooltmpl 0185f4e0cf02" + labelother: "merge rev: tooltmpl 0185f4e0cf02" output (arg): "$TESTTMP/repo/f" output (contents): <<<<<<< working copy: tooltmpl ef83787e2614