comparison mercurial/simplemerge.py @ 48754:d9602f0df4f3

simplemerge: remove code for checking binary input now that callers do it The callers now do the checking for binary inputs and handle warnings and/or errors, so we can remove that code from the low-level `simplemerge` module now. After this patch we just raise an error unless the caller told us to allow binary inputs. Differential Revision: https://phab.mercurial-scm.org/D12169
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 10 Feb 2022 15:48:01 -0800
parents 59c6724ddccb
children 6ae3c97a0919
comparison
equal deleted inserted replaced
48753:d9af7c1fb619 48754:d9602f0df4f3
270 sl.append((intbase, intbase, abase, abase, bbase, bbase)) 270 sl.append((intbase, intbase, abase, abase, bbase, bbase))
271 271
272 return sl 272 return sl
273 273
274 274
275 def _verifytext(text, path, ui, quiet=False, allow_binary=False): 275 def _verifytext(input):
276 """verifies that text is non-binary (unless opts[text] is passed, 276 """verifies that text is non-binary (unless opts[text] is passed,
277 then we just warn)""" 277 then we just warn)"""
278 if stringutil.binary(text): 278 if stringutil.binary(input.text()):
279 msg = _(b"%s looks like a binary file.") % path 279 msg = _(b"%s looks like a binary file.") % input.fctx.path()
280 if not quiet: 280 raise error.Abort(msg)
281 ui.warn(_(b'warning: %s\n') % msg)
282 if not allow_binary:
283 raise error.Abort(msg)
284 return text
285 281
286 282
287 def _format_labels(*inputs): 283 def _format_labels(*inputs):
288 pad = max(len(input.label) if input.label else 0 for input in inputs) 284 pad = max(len(input.label) if input.label else 0 for input in inputs)
289 labels = [] 285 labels = []
509 """Performs the simplemerge algorithm. 505 """Performs the simplemerge algorithm.
510 506
511 The merged result is written into `localctx`. 507 The merged result is written into `localctx`.
512 """ 508 """
513 509
514 def readctx(input): 510 if not allow_binary:
515 return _verifytext( 511 _verifytext(local)
516 input.text(), 512 _verifytext(base)
517 input.fctx.path(), 513 _verifytext(other)
518 ui, 514
519 quiet=quiet, 515 m3 = Merge3Text(base.text(), local.text(), other.text())
520 allow_binary=allow_binary,
521 )
522
523 try:
524 localtext = readctx(local)
525 basetext = readctx(base)
526 othertext = readctx(other)
527 except error.Abort:
528 return True
529
530 m3 = Merge3Text(basetext, localtext, othertext)
531 conflicts = False 516 conflicts = False
532 if mode == b'union': 517 if mode == b'union':
533 lines = _resolve(m3, (1, 2)) 518 lines = _resolve(m3, (1, 2))
534 elif mode == b'local': 519 elif mode == b'local':
535 lines = _resolve(m3, (1,)) 520 lines = _resolve(m3, (1,))