comparison mercurial/filemerge.py @ 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 3c8cc987672e
children 6ae3c97a0919
comparison
equal deleted inserted replaced
48752:109fec7bf7de 48753:d9af7c1fb619
38 util, 38 util,
39 ) 39 )
40 40
41 from .utils import ( 41 from .utils import (
42 procutil, 42 procutil,
43 stringutil,
43 ) 44 )
44 45
45 46
46 def _toolstr(ui, tool, part, *args): 47 def _toolstr(ui, tool, part, *args):
47 return ui.config(b"merge-tools", tool + b"." + part, *args) 48 return ui.config(b"merge-tools", tool + b"." + part, *args)
400 return filectx.changectx()[filectx.path()] 401 return filectx.changectx()[filectx.path()]
401 else: 402 else:
402 return filectx 403 return filectx
403 404
404 405
406 def _verifytext(input, ui):
407 """verifies that text is non-binary"""
408 if stringutil.binary(input.text()):
409 msg = _(b"%s looks like a binary file.") % input.fctx.path()
410 ui.warn(_(b'warning: %s\n') % msg)
411 raise error.Abort(msg)
412
413
405 def _premerge(repo, local, other, base, toolconf, backup): 414 def _premerge(repo, local, other, base, toolconf, backup):
406 tool, toolpath, binary, symlink, scriptfn = toolconf 415 tool, toolpath, binary, symlink, scriptfn = toolconf
407 if symlink or local.fctx.isabsent() or other.fctx.isabsent(): 416 if symlink or local.fctx.isabsent() or other.fctx.isabsent():
408 return 1 417 return 1
409 418
427 mode = b'merge' 436 mode = b'merge'
428 if premerge == b'keep-mergediff': 437 if premerge == b'keep-mergediff':
429 mode = b'mergediff' 438 mode = b'mergediff'
430 elif premerge == b'keep-merge3': 439 elif premerge == b'keep-merge3':
431 mode = b'merge3' 440 mode = b'merge3'
441 if any(
442 stringutil.binary(input.text()) for input in (local, base, other)
443 ):
444 return 1 # continue merging
432 r = simplemerge.simplemerge( 445 r = simplemerge.simplemerge(
433 ui, local, base, other, quiet=True, mode=mode 446 ui, local, base, other, quiet=True, mode=mode
434 ) 447 )
435 if not r: 448 if not r:
436 ui.debug(b" premerge successful\n") 449 ui.debug(b" premerge successful\n")
468 files. It will fail if there are any conflicts and leave markers in 481 files. It will fail if there are any conflicts and leave markers in
469 the partially merged file. Markers will have two sections, one for each side 482 the partially merged file. Markers will have two sections, one for each side
470 of merge, unless mode equals 'union' which suppresses the markers.""" 483 of merge, unless mode equals 'union' which suppresses the markers."""
471 ui = repo.ui 484 ui = repo.ui
472 485
486 try:
487 _verifytext(local, ui)
488 _verifytext(base, ui)
489 _verifytext(other, ui)
490 except error.Abort:
491 return True, True, False
473 r = simplemerge.simplemerge(ui, local, base, other, mode=mode) 492 r = simplemerge.simplemerge(ui, local, base, other, mode=mode)
474 return True, r, False 493 return True, r, False
475 494
476 495
477 @internaltool( 496 @internaltool(