Mercurial > hg-stable
changeset 48755:109fec7bf7de
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 10 Feb 2022 13:36:09 -0800 |
parents | 59c6724ddccb |
children | d9af7c1fb619 |
files | contrib/simplemerge |
diffstat | 1 files changed, 22 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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'), ) )