[Updated] D12146: simplemerge: let extension check for binary inputs (unless `--text`)

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Feb 15 12:56:20 UTC 2022


Closed by commit rHG109fec7bf7de: simplemerge: let extension check for binary inputs (unless `--text`) (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12146?vs=32135&id=32189

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D12146/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D12146

AFFECTED FILES
  contrib/simplemerge

CHANGE DETAILS

diff --git a/contrib/simplemerge b/contrib/simplemerge
--- a/contrib/simplemerge
+++ b/contrib/simplemerge
@@ -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'),
         )
     )



To: martinvonz, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220215/db0084f0/attachment-0002.html>


More information about the Mercurial-patches mailing list