##// END OF EJS Templates
simplemerge: take over formatting of label from `filemerge`...
Martin von Zweigbergk -
r49433:3c8cc987 default
parent child Browse files
Show More
@@ -40,7 +40,6 b' from . import ('
40 40
41 41 from .utils import (
42 42 procutil,
43 stringutil,
44 43 )
45 44
46 45
@@ -724,6 +723,13 b' def _xmerge(repo, mynode, local, other, '
724 723 ) as temppaths:
725 724 basepath, otherpath, localoutputpath = temppaths
726 725 outpath = b""
726
727 def format_label(input):
728 if input.label_detail:
729 return b'%s: %s' % (input.label, input.label_detail)
730 else:
731 return input.label
732
727 733 env = {
728 734 b'HG_FILE': fcd.path(),
729 735 b'HG_MY_NODE': short(mynode),
@@ -732,9 +738,9 b' def _xmerge(repo, mynode, local, other, '
732 738 b'HG_MY_ISLINK': b'l' in fcd.flags(),
733 739 b'HG_OTHER_ISLINK': b'l' in fco.flags(),
734 740 b'HG_BASE_ISLINK': b'l' in fca.flags(),
735 b'HG_MY_LABEL': local.label,
736 b'HG_OTHER_LABEL': other.label,
737 b'HG_BASE_LABEL': base.label,
741 b'HG_MY_LABEL': format_label(local),
742 b'HG_OTHER_LABEL': format_label(other),
743 b'HG_BASE_LABEL': format_label(base),
738 744 }
739 745 ui = repo.ui
740 746
@@ -747,9 +753,9 b' def _xmerge(repo, mynode, local, other, '
747 753 b'base': basepath,
748 754 b'other': otherpath,
749 755 b'output': outpath,
750 b'labellocal': local.label,
751 b'labelother': other.label,
752 b'labelbase': base.label,
756 b'labellocal': format_label(local),
757 b'labelother': format_label(other),
758 b'labelbase': format_label(base),
753 759 }
754 760 args = util.interpolate(
755 761 br'\$',
@@ -801,32 +807,19 b' def _xmerge(repo, mynode, local, other, '
801 807 return True, r, False
802 808
803 809
804 def _populate_label_detail(input, template, pad):
805 """Applies the given template to the ctx, prefixed by the label.
806
807 Pad is the minimum width of the label prefix, so that multiple markers
808 can have aligned templated parts.
809 """
810 def _populate_label_detail(input, template):
811 """Applies the given template to the ctx and stores it in the input."""
810 812 ctx = input.fctx.changectx()
811 813 if ctx.node() is None:
812 814 ctx = ctx.p1()
813 815
814 816 props = {b'ctx': ctx}
815 817 templateresult = template.renderdefault(props)
816
817 label = (b'%s:' % input.label).ljust(pad + 1)
818 mark = b'%s %s' % (label, templateresult)
819 mark = mark.splitlines()[0] # split for safety
820
821 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
822 input.label = stringutil.ellipsis(mark, 80 - 8)
818 input.label_detail = templateresult.splitlines()[0] # split for safety
823 819
824 820
825 821 def _populate_label_details(repo, inputs, tool=None):
826 """Formats the given labels using the conflict marker template.
827
828 Returns a list of formatted labels.
829 """
822 """Populates the label details using the conflict marker template."""
830 823 ui = repo.ui
831 824 template = ui.config(b'command-templates', b'mergemarker')
832 825 if tool is not None:
@@ -837,10 +830,8 b' def _populate_label_details(repo, inputs'
837 830 ui, template, defaults=templatekw.keywords, resources=tres
838 831 )
839 832
840 pad = max(len(input.label) for input in inputs)
841
842 833 for input in inputs:
843 _populate_label_detail(input, tmpl, pad)
834 _populate_label_detail(input, tmpl)
844 835
845 836
846 837 def partextras(labels):
@@ -1111,9 +1102,9 b' def filemerge(repo, wctx, mynode, orig, '
1111 1102 return r, False
1112 1103
1113 1104 # Reset to basic labels
1114 local.label = labels[0]
1115 other.label = labels[1]
1116 base.label = labels[2]
1105 local.label_detail = None
1106 other.label_detail = None
1107 base.label_detail = None
1117 1108
1118 1109 if markerstyle != b'basic':
1119 1110 _populate_label_details(repo, [local, other, base], tool=tool)
@@ -286,10 +286,20 b' def _verifytext(text, path, ui, opts):'
286 286
287 287
288 288 def _format_labels(*inputs):
289 pad = max(len(input.label) if input.label else 0 for input in inputs)
289 290 labels = []
290 291 for input in inputs:
291 292 if input.label:
292 labels.append(input.label)
293 if input.label_detail:
294 label = (
295 (input.label + b':').ljust(pad + 1)
296 + b' '
297 + input.label_detail
298 )
299 else:
300 label = input.label
301 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
302 labels.append(stringutil.ellipsis(label, 80 - 8))
293 303 else:
294 304 labels.append(None)
295 305 return labels
@@ -468,6 +478,10 b' def _resolve(m3, sides):'
468 478 class MergeInput(object):
469 479 fctx = attr.ib()
470 480 label = attr.ib(default=None)
481 # If the "detail" part is set, then that is rendered after the label and
482 # separated by a ':'. The label is padded to make the ':' aligned among all
483 # merge inputs.
484 label_detail = attr.ib(default=None)
471 485
472 486
473 487 def simplemerge(ui, local, base, other, **opts):
@@ -18,6 +18,12 b' The `--no-check` and `--no-merge` now pr'
18 18 The remotefilelog extension now requires an appropiate excludepattern
19 19 for subrepositories.
20 20
21 The labels passed to merge tools have changed slightly. Merge tools can get
22 labels passed to them if you include `$labellocal`, `$labelbase`, and/or
23 `$labelother` in the `merge-tool.<tool name>.args` configuration. These labels
24 used to have some space-padding, and truncation to fit within 72 columns. Both
25 the padding and the truncation has been removed.
26
21 27 == Internal API Changes ==
22 28
23 29 The following functions have been removed:
@@ -1648,7 +1648,7 b' mergemarkertemplate:'
1648 1648 merging f
1649 1649 arg: "ll:working copy: tooltmpl ef83787e2614"
1650 1650 arg: "lo:"
1651 arg: "merge rev: tooltmpl 0185f4e0cf02"
1651 arg: "merge rev: tooltmpl 0185f4e0cf02"
1652 1652 arg: "lb:base: */f~base.*" (glob)
1653 1653 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1654 1654 (branch merge, don't forget to commit)
@@ -1718,7 +1718,7 b' mergemarkers=detailed; labellocal and la'
1718 1718 > merge -r 2
1719 1719 merging f
1720 1720 labellocal: "working copy: tooltmpl ef83787e2614"
1721 labelother: "merge rev: tooltmpl 0185f4e0cf02"
1721 labelother: "merge rev: tooltmpl 0185f4e0cf02"
1722 1722 output (arg): "$TESTTMP/repo/f"
1723 1723 output (contents):
1724 1724 <<<<<<< working copy: tooltmpl ef83787e2614
General Comments 0
You need to be logged in to leave comments. Login now