# HG changeset patch # User Martin von Zweigbergk # Date 1644528969 28800 # Node ID 109fec7bf7de60d9cf231f821882fe1655fb58a4 # Parent 59c6724ddccb6cb1df2a6bc5c17d18fc76a7a2c3 simplemerge: let extension check for binary inputs (unless `--text`) The `simplemerge` module does too much UI-related things. This patch puts a specialized copy of `simplemerge._verifytext()` in the simplemerge extension. Differential Revision: https://phab.mercurial-scm.org/D12146 diff -r 59c6724ddccb -r 109fec7bf7de contrib/simplemerge --- a/contrib/simplemerge Thu Feb 10 11:00:32 2022 -0800 +++ b/contrib/simplemerge Thu Feb 10 13:36:09 2022 -0800 @@ -64,6 +64,17 @@ procutil.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) +def _verifytext(input, ui, quiet=False, allow_binary=False): + """verifies that text is non-binary (unless opts[text] is passed, + then we just warn)""" + if stringutil.binary(input.text()): + msg = _(b"%s looks like a binary file.") % input.fctx.path() + if not quiet: + ui.warn(_(b'warning: %s\n') % msg) + if not allow_binary: + sys.exit(1) + + try: for fp in (sys.stdin, procutil.stdout, sys.stderr): procutil.setbinary(fp) @@ -97,15 +108,23 @@ base_input = simplemerge.MergeInput( context.arbitraryfilectx(base), labels[2] ) + + quiet = opts.get(b'quiet') + allow_binary = opts.get(b'text') + ui = uimod.ui.load() + _verifytext(local_input, ui, quiet=quiet, allow_binary=allow_binary) + _verifytext(base_input, ui, quiet=quiet, allow_binary=allow_binary) + _verifytext(other_input, ui, quiet=quiet, allow_binary=allow_binary) + sys.exit( simplemerge.simplemerge( - uimod.ui.load(), + ui, local_input, base_input, other_input, mode, - quiet=opts.get(b'quiet'), - allow_binary=opts.get(b'text'), + quiet=True, + allow_binary=allow_binary, print_result=opts.get(b'print'), ) )