Mercurial > public > mercurial-scm > hg
comparison mercurial/simplemerge.py @ 48749:9ee70e175fed
simplemerge: replace `**opts` passed to `simplemerge()` by keyword arguments
The `simplemerge` module is library code; it should not get an
unmodified `opts` dict from the `simplemerge` extension.
Differential Revision: https://phab.mercurial-scm.org/D12152
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 10 Feb 2022 09:59:07 -0800 |
parents | 3c8cc987672e |
children | aed8ef33db8b |
comparison
equal
deleted
inserted
replaced
48746:18e69f224e4b | 48749:9ee70e175fed |
---|---|
271 sl.append((intbase, intbase, abase, abase, bbase, bbase)) | 271 sl.append((intbase, intbase, abase, abase, bbase, bbase)) |
272 | 272 |
273 return sl | 273 return sl |
274 | 274 |
275 | 275 |
276 def _verifytext(text, path, ui, opts): | 276 def _verifytext(text, path, ui, quiet=False, allow_binary=False): |
277 """verifies that text is non-binary (unless opts[text] is passed, | 277 """verifies that text is non-binary (unless opts[text] is passed, |
278 then we just warn)""" | 278 then we just warn)""" |
279 if stringutil.binary(text): | 279 if stringutil.binary(text): |
280 msg = _(b"%s looks like a binary file.") % path | 280 msg = _(b"%s looks like a binary file.") % path |
281 if not opts.get('quiet'): | 281 if not quiet: |
282 ui.warn(_(b'warning: %s\n') % msg) | 282 ui.warn(_(b'warning: %s\n') % msg) |
283 if not opts.get('text'): | 283 if not allow_binary: |
284 raise error.Abort(msg) | 284 raise error.Abort(msg) |
285 return text | 285 return text |
286 | 286 |
287 | 287 |
288 def _format_labels(*inputs): | 288 def _format_labels(*inputs): |
482 # separated by a ':'. The label is padded to make the ':' aligned among all | 482 # separated by a ':'. The label is padded to make the ':' aligned among all |
483 # merge inputs. | 483 # merge inputs. |
484 label_detail = attr.ib(default=None) | 484 label_detail = attr.ib(default=None) |
485 | 485 |
486 | 486 |
487 def simplemerge(ui, local, base, other, **opts): | 487 def simplemerge( |
488 ui, | |
489 local, | |
490 base, | |
491 other, | |
492 mode=b'merge', | |
493 quiet=False, | |
494 allow_binary=False, | |
495 print_result=False, | |
496 ): | |
488 """Performs the simplemerge algorithm. | 497 """Performs the simplemerge algorithm. |
489 | 498 |
490 The merged result is written into `localctx`. | 499 The merged result is written into `localctx`. |
491 """ | 500 """ |
492 | 501 |
496 # filters. | 505 # filters. |
497 # | 506 # |
498 # Maintain that behavior today for BC, though perhaps in the future | 507 # Maintain that behavior today for BC, though perhaps in the future |
499 # it'd be worth considering whether merging encoded data (what the | 508 # it'd be worth considering whether merging encoded data (what the |
500 # repository usually sees) might be more useful. | 509 # repository usually sees) might be more useful. |
501 return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts) | 510 return _verifytext( |
511 ctx.decodeddata(), | |
512 ctx.path(), | |
513 ui, | |
514 quiet=quiet, | |
515 allow_binary=allow_binary, | |
516 ) | |
502 | 517 |
503 try: | 518 try: |
504 localtext = readctx(local.fctx) | 519 localtext = readctx(local.fctx) |
505 basetext = readctx(base.fctx) | 520 basetext = readctx(base.fctx) |
506 othertext = readctx(other.fctx) | 521 othertext = readctx(other.fctx) |
507 except error.Abort: | 522 except error.Abort: |
508 return True | 523 return True |
509 | 524 |
510 m3 = Merge3Text(basetext, localtext, othertext) | 525 m3 = Merge3Text(basetext, localtext, othertext) |
511 conflicts = False | 526 conflicts = False |
512 mode = opts.get('mode', b'merge') | |
513 if mode == b'union': | 527 if mode == b'union': |
514 lines = _resolve(m3, (1, 2)) | 528 lines = _resolve(m3, (1, 2)) |
515 elif mode == b'local': | 529 elif mode == b'local': |
516 lines = _resolve(m3, (1,)) | 530 lines = _resolve(m3, (1,)) |
517 elif mode == b'other': | 531 elif mode == b'other': |
526 else: | 540 else: |
527 labels = _format_labels(local, other) | 541 labels = _format_labels(local, other) |
528 lines, conflicts = render_minimized(m3, *labels) | 542 lines, conflicts = render_minimized(m3, *labels) |
529 | 543 |
530 mergedtext = b''.join(lines) | 544 mergedtext = b''.join(lines) |
531 if opts.get('print'): | 545 if print_result: |
532 ui.fout.write(mergedtext) | 546 ui.fout.write(mergedtext) |
533 else: | 547 else: |
534 # local.fctx.flags() already has the merged flags (done in | 548 # local.fctx.flags() already has the merged flags (done in |
535 # mergestate.resolve()) | 549 # mergestate.resolve()) |
536 local.fctx.write(mergedtext, local.fctx.flags()) | 550 local.fctx.write(mergedtext, local.fctx.flags()) |