[Updated] D12147: simplemerge: let filemerge check for binary inputs
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Fri Feb 11 02:55:45 UTC 2022
martinvonz edited the summary of this revision.
martinvonz retitled this revision from "simplemerge: let users call verifytext()" to "simplemerge: let filemerge check for binary inputs".
martinvonz updated this revision to Diff 32136.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D12147?vs=32096&id=32136
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D12147/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D12147
AFFECTED FILES
mercurial/filemerge.py
CHANGE DETAILS
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -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
To: martinvonz, #hg-reviewers
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220211/1c4df040/attachment-0002.html>
More information about the Mercurial-patches
mailing list