##// END OF EJS Templates
simplemerge: take arguments as annotated context objects...
Martin von Zweigbergk -
r49427:77e24ee8 default
parent child Browse files
Show More
@@ -84,15 +84,25 b' try:'
84 opts[b'mode'] = b'merge3'
84 opts[b'mode'] = b'merge3'
85 local, base, other = args
85 local, base, other = args
86 overrides = opts[b'label']
86 overrides = opts[b'label']
87 if len(overrides) > 3:
88 raise error.InputError(b'can only specify three labels.')
87 labels = [local, other, base]
89 labels = [local, other, base]
88 labels[: len(overrides)] = overrides
90 labels[: len(overrides)] = overrides
89 opts[b'label'] = labels
91 local_input = simplemerge.MergeInput(
92 context.arbitraryfilectx(local), labels[0]
93 )
94 other_input = simplemerge.MergeInput(
95 context.arbitraryfilectx(other), labels[1]
96 )
97 base_input = simplemerge.MergeInput(
98 context.arbitraryfilectx(base), labels[2]
99 )
90 sys.exit(
100 sys.exit(
91 simplemerge.simplemerge(
101 simplemerge.simplemerge(
92 uimod.ui.load(),
102 uimod.ui.load(),
93 context.arbitraryfilectx(local),
103 local_input,
94 context.arbitraryfilectx(base),
104 base_input,
95 context.arbitraryfilectx(other),
105 other_input,
96 **pycompat.strkwargs(opts)
106 **pycompat.strkwargs(opts)
97 )
107 )
98 )
108 )
@@ -428,8 +428,11 b' def _premerge(repo, fcd, fco, fca, toolc'
428 mode = b'mergediff'
428 mode = b'mergediff'
429 elif premerge == b'keep-merge3':
429 elif premerge == b'keep-merge3':
430 mode = b'merge3'
430 mode = b'merge3'
431 local = simplemerge.MergeInput(fcd, labels[0])
432 other = simplemerge.MergeInput(fco, labels[1])
433 base = simplemerge.MergeInput(fca, labels[2])
431 r = simplemerge.simplemerge(
434 r = simplemerge.simplemerge(
432 ui, fcd, fca, fco, quiet=True, label=labels, mode=mode
435 ui, local, base, other, quiet=True, mode=mode
433 )
436 )
434 if not r:
437 if not r:
435 ui.debug(b" premerge successful\n")
438 ui.debug(b" premerge successful\n")
@@ -469,7 +472,16 b' def _merge(repo, mynode, fcd, fco, fca, '
469 of merge, unless mode equals 'union' which suppresses the markers."""
472 of merge, unless mode equals 'union' which suppresses the markers."""
470 ui = repo.ui
473 ui = repo.ui
471
474
472 r = simplemerge.simplemerge(ui, fcd, fca, fco, label=labels, mode=mode)
475 local = simplemerge.MergeInput(fcd)
476 if len(labels) > 0:
477 local.label = labels[0]
478 other = simplemerge.MergeInput(fco)
479 if len(labels) > 1:
480 other.label = labels[1]
481 base = simplemerge.MergeInput(fca)
482 if len(labels) > 2:
483 base.label = labels[2]
484 r = simplemerge.simplemerge(ui, local, base, other, mode=mode)
473 return True, r, False
485 return True, r, False
474
486
475
487
@@ -19,6 +19,7 b''
19 from __future__ import absolute_import
19 from __future__ import absolute_import
20
20
21 from .i18n import _
21 from .i18n import _
22 from .thirdparty import attr
22 from . import (
23 from . import (
23 error,
24 error,
24 mdiff,
25 mdiff,
@@ -284,13 +285,14 b' def _verifytext(text, path, ui, opts):'
284 return text
285 return text
285
286
286
287
287 def _picklabels(overrides):
288 def _format_labels(*inputs):
288 if len(overrides) > 3:
289 labels = []
289 raise error.Abort(_(b"can only specify three labels."))
290 for input in inputs:
290 result = [None, None, None]
291 if input.label:
291 for i, override in enumerate(overrides):
292 labels.append(input.label)
292 result[i] = override
293 else:
293 return result
294 labels.append(None)
295 return labels
294
296
295
297
296 def _detect_newline(m3):
298 def _detect_newline(m3):
@@ -462,7 +464,13 b' def _resolve(m3, sides):'
462 return lines
464 return lines
463
465
464
466
465 def simplemerge(ui, localctx, basectx, otherctx, **opts):
467 @attr.s
468 class MergeInput(object):
469 fctx = attr.ib()
470 label = attr.ib(default=None)
471
472
473 def simplemerge(ui, local, base, other, **opts):
466 """Performs the simplemerge algorithm.
474 """Performs the simplemerge algorithm.
467
475
468 The merged result is written into `localctx`.
476 The merged result is written into `localctx`.
@@ -479,9 +487,9 b' def simplemerge(ui, localctx, basectx, o'
479 return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts)
487 return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts)
480
488
481 try:
489 try:
482 localtext = readctx(localctx)
490 localtext = readctx(local.fctx)
483 basetext = readctx(basectx)
491 basetext = readctx(base.fctx)
484 othertext = readctx(otherctx)
492 othertext = readctx(other.fctx)
485 except error.Abort:
493 except error.Abort:
486 return True
494 return True
487
495
@@ -495,20 +503,22 b' def simplemerge(ui, localctx, basectx, o'
495 elif mode == b'other':
503 elif mode == b'other':
496 lines = _resolve(m3, (2,))
504 lines = _resolve(m3, (2,))
497 else:
505 else:
498 name_a, name_b, name_base = _picklabels(opts.get('label', []))
499 if mode == b'mergediff':
506 if mode == b'mergediff':
500 lines, conflicts = render_mergediff(m3, name_a, name_b, name_base)
507 labels = _format_labels(local, other, base)
508 lines, conflicts = render_mergediff(m3, *labels)
501 elif mode == b'merge3':
509 elif mode == b'merge3':
502 lines, conflicts = render_merge3(m3, name_a, name_b, name_base)
510 labels = _format_labels(local, other, base)
511 lines, conflicts = render_merge3(m3, *labels)
503 else:
512 else:
504 lines, conflicts = render_minimized(m3, name_a, name_b)
513 labels = _format_labels(local, other)
514 lines, conflicts = render_minimized(m3, *labels)
505
515
506 mergedtext = b''.join(lines)
516 mergedtext = b''.join(lines)
507 if opts.get('print'):
517 if opts.get('print'):
508 ui.fout.write(mergedtext)
518 ui.fout.write(mergedtext)
509 else:
519 else:
510 # localctx.flags() already has the merged flags (done in
520 # local.fctx.flags() already has the merged flags (done in
511 # mergestate.resolve())
521 # mergestate.resolve())
512 localctx.write(mergedtext, localctx.flags())
522 local.fctx.write(mergedtext, local.fctx.flags())
513
523
514 return conflicts
524 return conflicts
General Comments 0
You need to be logged in to leave comments. Login now