[PATCH 1 of 5] simplemerge: extract verifytext as a helper function

Phil Cohen phillco at fb.com
Mon Jul 3 04:40:15 UTC 2017


# HG changeset patch
# User Phil Cohen <phillco at fb.com>
# Date 200 28800
#      Wed Dec 31 16:03:20 1969 -0800
# Node ID c33a1225fcbc5cc2c13391fe4f72d329abbe6129
# Parent  016ce3d8fee0968dd30894bf78c3812a19a240d9
simplemerge: extract verifytext as a helper function

This will be used in a subsequent commit.

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -396,18 +396,23 @@
 
         return unc
 
+def _verifytext(text, path, ui, opts):
+    """verifies that text is non-binary (unless opts[text] is passed,
+    then we just warn)"""
+    if util.binary(text):
+        msg = _("%s looks like a binary file.") % path
+        if not opts.get('quiet'):
+            ui.warn(_('warning: %s\n') % msg)
+        if not opts.get('text'):
+            raise error.Abort(msg)
+    return text
+
 def simplemerge(ui, local, base, other, **opts):
     def readfile(filename):
         f = open(filename, "rb")
         text = f.read()
         f.close()
-        if util.binary(text):
-            msg = _("%s looks like a binary file.") % filename
-            if not opts.get('quiet'):
-                ui.warn(_('warning: %s\n') % msg)
-            if not opts.get('text'):
-                raise error.Abort(msg)
-        return text
+        return _verifytext(text, filename, ui, opts)
 
     mode = opts.get('mode','merge')
     if mode == 'union':


More information about the Mercurial-devel mailing list