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