simplemerge: let filemerge check for binary inputs
This is similar to the previous patch, but here we put a specialized
copy of `simplemerge._verifytext()` in the the `filemerge` module
instead.
Differential Revision: https://phab.mercurial-scm.org/D12147
--- a/mercurial/filemerge.py Thu Feb 10 13:36:09 2022 -0800
+++ b/mercurial/filemerge.py Thu Feb 10 15:27:58 2022 -0800
@@ -40,6 +40,7 @@
from .utils import (
procutil,
+ stringutil,
)
@@ -402,6 +403,14 @@
return filectx
+def _verifytext(input, ui):
+ """verifies that text is non-binary"""
+ if stringutil.binary(input.text()):
+ msg = _(b"%s looks like a binary file.") % input.fctx.path()
+ ui.warn(_(b'warning: %s\n') % msg)
+ raise error.Abort(msg)
+
+
def _premerge(repo, local, other, base, toolconf, backup):
tool, toolpath, binary, symlink, scriptfn = toolconf
if symlink or local.fctx.isabsent() or other.fctx.isabsent():
@@ -429,6 +438,10 @@
mode = b'mergediff'
elif premerge == b'keep-merge3':
mode = b'merge3'
+ if any(
+ stringutil.binary(input.text()) for input in (local, base, other)
+ ):
+ return 1 # continue merging
r = simplemerge.simplemerge(
ui, local, base, other, quiet=True, mode=mode
)
@@ -470,6 +483,12 @@
of merge, unless mode equals 'union' which suppresses the markers."""
ui = repo.ui
+ try:
+ _verifytext(local, ui)
+ _verifytext(base, ui)
+ _verifytext(other, ui)
+ except error.Abort:
+ return True, True, False
r = simplemerge.simplemerge(ui, local, base, other, mode=mode)
return True, r, False