[Updated] D12147: simplemerge: let filemerge check for binary inputs

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Feb 15 12:56:29 UTC 2022


Closed by commit rHGd9af7c1fb619: simplemerge: let filemerge check for binary inputs (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12147?vs=32136&id=32190

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, Alphare
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220215/21af981a/attachment-0002.html>


More information about the Mercurial-patches mailing list