Mercurial > hg
changeset 48587:3c8cc987672e
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 20 Jan 2022 11:06:52 -0800 |
parents | fd9fe2658cda |
children | 402a6b6173e9 |
files | mercurial/filemerge.py mercurial/simplemerge.py relnotes/next tests/test-merge-tools.t |
diffstat | 4 files changed, 44 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/filemerge.py Thu Jan 20 16:16:05 2022 -0800 +++ b/mercurial/filemerge.py Thu Jan 20 11:06:52 2022 -0800 @@ -40,7 +40,6 @@ from .utils import ( procutil, - stringutil, ) @@ -724,6 +723,13 @@ ) 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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)
--- a/mercurial/simplemerge.py Thu Jan 20 16:16:05 2022 -0800 +++ b/mercurial/simplemerge.py Thu Jan 20 11:06:52 2022 -0800 @@ -286,10 +286,20 @@ 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 @@ 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):
--- a/relnotes/next Thu Jan 20 16:16:05 2022 -0800 +++ b/relnotes/next Thu Jan 20 11:06:52 2022 -0800 @@ -18,6 +18,12 @@ 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.<tool name>.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:
--- a/tests/test-merge-tools.t Thu Jan 20 16:16:05 2022 -0800 +++ b/tests/test-merge-tools.t Thu Jan 20 11:06:52 2022 -0800 @@ -1648,7 +1648,7 @@ 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 @@ > 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