[Updated] D12019: simplemerge: take over formatting of label from `filemerge`

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Jan 24 17:32:08 UTC 2022


Closed by commit rHG3c8cc987672e: simplemerge: take over formatting of label from `filemerge` (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/D12019?vs=31821&id=31832

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D12019/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D12019

AFFECTED FILES
  mercurial/filemerge.py
  mercurial/simplemerge.py
  relnotes/next
  tests/test-merge-tools.t

CHANGE DETAILS

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 @@
   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
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -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:
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -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):
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -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)



To: martinvonz, #hg-reviewers, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220124/0e83117b/attachment-0002.html>


More information about the Mercurial-patches mailing list