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

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Feb 11 02:55:43 UTC 2022


martinvonz edited the summary of this revision.
martinvonz retitled this revision from "simplemerge: make _verifytext() callable by simplemerge's users" to "simplemerge: let extension check for binary inputs (unless `--text`)".
martinvonz updated this revision to Diff 32135.

REPOSITORY
  rHG Mercurial

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

BRANCH
  default

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/20220211/a67e3742/attachment-0002.html>


More information about the Mercurial-patches mailing list