changeset 48753:d9af7c1fb619

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
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 10 Feb 2022 15:27:58 -0800
parents 109fec7bf7de
children d9602f0df4f3
files mercurial/filemerge.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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