##// END OF EJS Templates
filemerge: work with `simplemerge.MergeInput` in `filemerge()`...
Martin von Zweigbergk -
r49431:07069fcd default
parent child Browse files
Show More
@@ -805,35 +805,32 def _xmerge(repo, mynode, fcd, fco, fca,
805 return True, r, False
805 return True, r, False
806
806
807
807
808 def _formatlabel(ctx, template, label, pad):
808 def _formatlabel(input, template, pad):
809 """Applies the given template to the ctx, prefixed by the label.
809 """Applies the given template to the ctx, prefixed by the label.
810
810
811 Pad is the minimum width of the label prefix, so that multiple markers
811 Pad is the minimum width of the label prefix, so that multiple markers
812 can have aligned templated parts.
812 can have aligned templated parts.
813 """
813 """
814 ctx = input.fctx.changectx()
814 if ctx.node() is None:
815 if ctx.node() is None:
815 ctx = ctx.p1()
816 ctx = ctx.p1()
816
817
817 props = {b'ctx': ctx}
818 props = {b'ctx': ctx}
818 templateresult = template.renderdefault(props)
819 templateresult = template.renderdefault(props)
819
820
820 label = (b'%s:' % label).ljust(pad + 1)
821 label = (b'%s:' % input.label).ljust(pad + 1)
821 mark = b'%s %s' % (label, templateresult)
822 mark = b'%s %s' % (label, templateresult)
822 mark = mark.splitlines()[0] # split for safety
823 mark = mark.splitlines()[0] # split for safety
823
824
824 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
825 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
825 return stringutil.ellipsis(mark, 80 - 8)
826 input.label = stringutil.ellipsis(mark, 80 - 8)
826
827
827
828
828 def _formatlabels(repo, fcd, fco, fca, labels, tool=None):
829 def _formatlabels(repo, inputs, tool=None):
829 """Formats the given labels using the conflict marker template.
830 """Formats the given labels using the conflict marker template.
830
831
831 Returns a list of formatted labels.
832 Returns a list of formatted labels.
832 """
833 """
833 cd = fcd.changectx()
834 co = fco.changectx()
835 ca = fca.changectx()
836
837 ui = repo.ui
834 ui = repo.ui
838 template = ui.config(b'command-templates', b'mergemarker')
835 template = ui.config(b'command-templates', b'mergemarker')
839 if tool is not None:
836 if tool is not None:
@@ -844,14 +841,9 def _formatlabels(repo, fcd, fco, fca, l
844 ui, template, defaults=templatekw.keywords, resources=tres
841 ui, template, defaults=templatekw.keywords, resources=tres
845 )
842 )
846
843
847 pad = max(len(l) for l in labels)
844 pad = max(len(input.label) for input in inputs)
848
845
849 newlabels = [
846 return [_formatlabel(input, tmpl, pad) for input in inputs]
850 _formatlabel(cd, tmpl, labels[0], pad),
851 _formatlabel(co, tmpl, labels[1], pad),
852 _formatlabel(ca, tmpl, labels[2], pad),
853 ]
854 return newlabels
855
847
856
848
857 def partextras(labels):
849 def partextras(labels):
@@ -1052,8 +1044,19 def filemerge(repo, wctx, mynode, orig,
1052 labels = [b'local', b'other']
1044 labels = [b'local', b'other']
1053 if len(labels) < 3:
1045 if len(labels) < 3:
1054 labels.append(b'base')
1046 labels.append(b'base')
1047 local = simplemerge.MergeInput(fcd, labels[0])
1048 other = simplemerge.MergeInput(fco, labels[1])
1049 base = simplemerge.MergeInput(fca, labels[2])
1055 if mergetype == nomerge:
1050 if mergetype == nomerge:
1056 return func(repo, mynode, fcd, fco, fca, toolconf, labels)
1051 return func(
1052 repo,
1053 mynode,
1054 fcd,
1055 fco,
1056 fca,
1057 toolconf,
1058 [local.label, other.label, base.label],
1059 )
1057
1060
1058 if orig != fco.path():
1061 if orig != fco.path():
1059 ui.status(
1062 ui.status(
@@ -1083,36 +1086,41 def filemerge(repo, wctx, mynode, orig,
1083 else:
1086 else:
1084 markerstyle = internalmarkerstyle
1087 markerstyle = internalmarkerstyle
1085
1088
1086 formattedlabels = labels
1087 if markerstyle != b'basic':
1088 formattedlabels = _formatlabels(
1089 repo, fcd, fco, fca, labels, tool=tool
1090 )
1091
1092 if mergetype == fullmerge:
1089 if mergetype == fullmerge:
1093 # conflict markers generated by premerge will use 'detailed'
1090 # conflict markers generated by premerge will use 'detailed'
1094 # settings if either ui.mergemarkers or the tool's mergemarkers
1091 # settings if either ui.mergemarkers or the tool's mergemarkers
1095 # setting is 'detailed'. This way tools can have basic labels in
1092 # setting is 'detailed'. This way tools can have basic labels in
1096 # space-constrained areas of the UI, but still get full information
1093 # space-constrained areas of the UI, but still get full information
1097 # in conflict markers if premerge is 'keep' or 'keep-merge3'.
1094 # in conflict markers if premerge is 'keep' or 'keep-merge3'.
1098 premergelabels = labels
1099 labeltool = None
1095 labeltool = None
1100 if markerstyle != b'basic':
1096 if markerstyle != b'basic':
1101 # respect 'tool's mergemarkertemplate (which defaults to
1097 # respect 'tool's mergemarkertemplate (which defaults to
1102 # command-templates.mergemarker)
1098 # command-templates.mergemarker)
1103 labeltool = tool
1099 labeltool = tool
1104 if internalmarkerstyle != b'basic' or markerstyle != b'basic':
1100 if internalmarkerstyle != b'basic' or markerstyle != b'basic':
1105 premergelabels = _formatlabels(
1101 _formatlabels(repo, [local, other, base], tool=labeltool)
1106 repo, fcd, fco, fca, premergelabels, tool=labeltool
1107 )
1108
1102
1109 r = _premerge(
1103 r = _premerge(
1110 repo, fcd, fco, fca, toolconf, backup, labels=premergelabels
1104 repo,
1105 fcd,
1106 fco,
1107 fca,
1108 toolconf,
1109 backup,
1110 labels=[local.label, other.label, base.label],
1111 )
1111 )
1112 # we're done if premerge was successful (r is 0)
1112 # we're done if premerge was successful (r is 0)
1113 if not r:
1113 if not r:
1114 return r, False
1114 return r, False
1115
1115
1116 # Reset to basic labels
1117 local.label = labels[0]
1118 other.label = labels[1]
1119 base.label = labels[2]
1120
1121 if markerstyle != b'basic':
1122 _formatlabels(repo, [local, other, base], tool=tool)
1123
1116 needcheck, r, deleted = func(
1124 needcheck, r, deleted = func(
1117 repo,
1125 repo,
1118 mynode,
1126 mynode,
@@ -1121,7 +1129,7 def filemerge(repo, wctx, mynode, orig,
1121 fca,
1129 fca,
1122 toolconf,
1130 toolconf,
1123 backup,
1131 backup,
1124 labels=formattedlabels,
1132 labels=[local.label, other.label, base.label],
1125 )
1133 )
1126
1134
1127 if needcheck:
1135 if needcheck:
General Comments 0
You need to be logged in to leave comments. Login now