# HG changeset patch # User Phil Cohen # Date 1502680012 25200 # Node ID de573184686e01c9d56c0ee79d0bcdc81e310370 # Parent 158dddc635ff6f29647c610ccab7dd02a9a5e1e4 simplemerge: extract verifytext as a helper function This will be used in a subsequent commit. Differential Revision: https://phab.mercurial-scm.org/D371 diff -r 158dddc635ff -r de573184686e mercurial/simplemerge.py --- a/mercurial/simplemerge.py Mon Aug 14 23:26:54 2017 -0700 +++ b/mercurial/simplemerge.py Sun Aug 13 20:06:52 2017 -0700 @@ -397,18 +397,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':