##// 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 from .utils import (
41 from .utils import (
42 procutil,
42 procutil,
43 stringutil,
44 )
43 )
45
44
46
45
@@ -724,6 +723,13 b' def _xmerge(repo, mynode, local, other, '
724 ) as temppaths:
723 ) as temppaths:
725 basepath, otherpath, localoutputpath = temppaths
724 basepath, otherpath, localoutputpath = temppaths
726 outpath = b""
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 env = {
733 env = {
728 b'HG_FILE': fcd.path(),
734 b'HG_FILE': fcd.path(),
729 b'HG_MY_NODE': short(mynode),
735 b'HG_MY_NODE': short(mynode),
@@ -732,9 +738,9 b' def _xmerge(repo, mynode, local, other, '
732 b'HG_MY_ISLINK': b'l' in fcd.flags(),
738 b'HG_MY_ISLINK': b'l' in fcd.flags(),
733 b'HG_OTHER_ISLINK': b'l' in fco.flags(),
739 b'HG_OTHER_ISLINK': b'l' in fco.flags(),
734 b'HG_BASE_ISLINK': b'l' in fca.flags(),
740 b'HG_BASE_ISLINK': b'l' in fca.flags(),
735 b'HG_MY_LABEL': local.label,
741 b'HG_MY_LABEL': format_label(local),
736 b'HG_OTHER_LABEL': other.label,
742 b'HG_OTHER_LABEL': format_label(other),
737 b'HG_BASE_LABEL': base.label,
743 b'HG_BASE_LABEL': format_label(base),
738 }
744 }
739 ui = repo.ui
745 ui = repo.ui
740
746
@@ -747,9 +753,9 b' def _xmerge(repo, mynode, local, other, '
747 b'base': basepath,
753 b'base': basepath,
748 b'other': otherpath,
754 b'other': otherpath,
749 b'output': outpath,
755 b'output': outpath,
750 b'labellocal': local.label,
756 b'labellocal': format_label(local),
751 b'labelother': other.label,
757 b'labelother': format_label(other),
752 b'labelbase': base.label,
758 b'labelbase': format_label(base),
753 }
759 }
754 args = util.interpolate(
760 args = util.interpolate(
755 br'\$',
761 br'\$',
@@ -801,32 +807,19 b' def _xmerge(repo, mynode, local, other, '
801 return True, r, False
807 return True, r, False
802
808
803
809
804 def _populate_label_detail(input, template, pad):
810 def _populate_label_detail(input, template):
805 """Applies the given template to the ctx, prefixed by the label.
811 """Applies the given template to the ctx and stores it in the input."""
806
807 Pad is the minimum width of the label prefix, so that multiple markers
808 can have aligned templated parts.
809 """
810 ctx = input.fctx.changectx()
812 ctx = input.fctx.changectx()
811 if ctx.node() is None:
813 if ctx.node() is None:
812 ctx = ctx.p1()
814 ctx = ctx.p1()
813
815
814 props = {b'ctx': ctx}
816 props = {b'ctx': ctx}
815 templateresult = template.renderdefault(props)
817 templateresult = template.renderdefault(props)
816
818 input.label_detail = templateresult.splitlines()[0] # split for safety
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)
823
819
824
820
825 def _populate_label_details(repo, inputs, tool=None):
821 def _populate_label_details(repo, inputs, tool=None):
826 """Formats the given labels using the conflict marker template.
822 """Populates the label details using the conflict marker template."""
827
828 Returns a list of formatted labels.
829 """
830 ui = repo.ui
823 ui = repo.ui
831 template = ui.config(b'command-templates', b'mergemarker')
824 template = ui.config(b'command-templates', b'mergemarker')
832 if tool is not None:
825 if tool is not None:
@@ -837,10 +830,8 b' def _populate_label_details(repo, inputs'
837 ui, template, defaults=templatekw.keywords, resources=tres
830 ui, template, defaults=templatekw.keywords, resources=tres
838 )
831 )
839
832
840 pad = max(len(input.label) for input in inputs)
841
842 for input in inputs:
833 for input in inputs:
843 _populate_label_detail(input, tmpl, pad)
834 _populate_label_detail(input, tmpl)
844
835
845
836
846 def partextras(labels):
837 def partextras(labels):
@@ -1111,9 +1102,9 b' def filemerge(repo, wctx, mynode, orig, '
1111 return r, False
1102 return r, False
1112
1103
1113 # Reset to basic labels
1104 # Reset to basic labels
1114 local.label = labels[0]
1105 local.label_detail = None
1115 other.label = labels[1]
1106 other.label_detail = None
1116 base.label = labels[2]
1107 base.label_detail = None
1117
1108
1118 if markerstyle != b'basic':
1109 if markerstyle != b'basic':
1119 _populate_label_details(repo, [local, other, base], tool=tool)
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 def _format_labels(*inputs):
288 def _format_labels(*inputs):
289 pad = max(len(input.label) if input.label else 0 for input in inputs)
289 labels = []
290 labels = []
290 for input in inputs:
291 for input in inputs:
291 if input.label:
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 else:
303 else:
294 labels.append(None)
304 labels.append(None)
295 return labels
305 return labels
@@ -468,6 +478,10 b' def _resolve(m3, sides):'
468 class MergeInput(object):
478 class MergeInput(object):
469 fctx = attr.ib()
479 fctx = attr.ib()
470 label = attr.ib(default=None)
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 def simplemerge(ui, local, base, other, **opts):
487 def simplemerge(ui, local, base, other, **opts):
@@ -18,6 +18,12 b' The `--no-check` and `--no-merge` now pr'
18 The remotefilelog extension now requires an appropiate excludepattern
18 The remotefilelog extension now requires an appropiate excludepattern
19 for subrepositories.
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 == Internal API Changes ==
27 == Internal API Changes ==
22
28
23 The following functions have been removed:
29 The following functions have been removed:
@@ -1648,7 +1648,7 b' mergemarkertemplate:'
1648 merging f
1648 merging f
1649 arg: "ll:working copy: tooltmpl ef83787e2614"
1649 arg: "ll:working copy: tooltmpl ef83787e2614"
1650 arg: "lo:"
1650 arg: "lo:"
1651 arg: "merge rev: tooltmpl 0185f4e0cf02"
1651 arg: "merge rev: tooltmpl 0185f4e0cf02"
1652 arg: "lb:base: */f~base.*" (glob)
1652 arg: "lb:base: */f~base.*" (glob)
1653 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1653 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1654 (branch merge, don't forget to commit)
1654 (branch merge, don't forget to commit)
@@ -1718,7 +1718,7 b' mergemarkers=detailed; labellocal and la'
1718 > merge -r 2
1718 > merge -r 2
1719 merging f
1719 merging f
1720 labellocal: "working copy: tooltmpl ef83787e2614"
1720 labellocal: "working copy: tooltmpl ef83787e2614"
1721 labelother: "merge rev: tooltmpl 0185f4e0cf02"
1721 labelother: "merge rev: tooltmpl 0185f4e0cf02"
1722 output (arg): "$TESTTMP/repo/f"
1722 output (arg): "$TESTTMP/repo/f"
1723 output (contents):
1723 output (contents):
1724 <<<<<<< working copy: tooltmpl ef83787e2614
1724 <<<<<<< working copy: tooltmpl ef83787e2614
General Comments 0
You need to be logged in to leave comments. Login now