simplemerge: remove code for checking binary input now that callers do it
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 10 Feb 2022 15:48:01 -0800
changeset 48757 d9602f0df4f3
parent 48756 d9af7c1fb619
child 48758 6ae3c97a0919
simplemerge: remove code for checking binary input now that callers do it The callers now do the checking for binary inputs and handle warnings and/or errors, so we can remove that code from the low-level `simplemerge` module now. After this patch we just raise an error unless the caller told us to allow binary inputs. Differential Revision: https://phab.mercurial-scm.org/D12169
mercurial/simplemerge.py
--- a/mercurial/simplemerge.py	Thu Feb 10 15:27:58 2022 -0800
+++ b/mercurial/simplemerge.py	Thu Feb 10 15:48:01 2022 -0800
@@ -272,16 +272,12 @@
         return sl
 
 
-def _verifytext(text, path, ui, quiet=False, allow_binary=False):
+def _verifytext(input):
     """verifies that text is non-binary (unless opts[text] is passed,
     then we just warn)"""
-    if stringutil.binary(text):
-        msg = _(b"%s looks like a binary file.") % path
-        if not quiet:
-            ui.warn(_(b'warning: %s\n') % msg)
-        if not allow_binary:
-            raise error.Abort(msg)
-    return text
+    if stringutil.binary(input.text()):
+        msg = _(b"%s looks like a binary file.") % input.fctx.path()
+        raise error.Abort(msg)
 
 
 def _format_labels(*inputs):
@@ -511,23 +507,12 @@
     The merged result is written into `localctx`.
     """
 
-    def readctx(input):
-        return _verifytext(
-            input.text(),
-            input.fctx.path(),
-            ui,
-            quiet=quiet,
-            allow_binary=allow_binary,
-        )
+    if not allow_binary:
+        _verifytext(local)
+        _verifytext(base)
+        _verifytext(other)
 
-    try:
-        localtext = readctx(local)
-        basetext = readctx(base)
-        othertext = readctx(other)
-    except error.Abort:
-        return True
-
-    m3 = Merge3Text(basetext, localtext, othertext)
+    m3 = Merge3Text(base.text(), local.text(), other.text())
     conflicts = False
     if mode == b'union':
         lines = _resolve(m3, (1, 2))