Patchwork D12169: simplemerge: remove code for checking binary input now that callers do it

login
register
mail settings
Submitter phabricator
Date Feb. 11, 2022, 2:55 a.m.
Message ID <differential-rev-PHID-DREV-i7rq3jiggwb3saufmbk3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50504/
State New
Headers show

Comments

phabricator - Feb. 11, 2022, 2:55 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -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))