comparison mercurial/simplemerge.py @ 33908:4074de97b512

simplemerge: simplify code now that we always write to a context There's no need for an `out` abstraction between files and contexts anymore. Differential Revision: https://phab.mercurial-scm.org/D383
author Phil Cohen <phillco@fb.com>
date Thu, 24 Aug 2017 21:30:51 -0700
parents 1ad3085239ad
children 3b2a002ef685
comparison
equal deleted inserted replaced
33907:1ad3085239ad 33908:4074de97b512
434 # Maintain that behavior today for BC, though perhaps in the future 434 # Maintain that behavior today for BC, though perhaps in the future
435 # it'd be worth considering whether merging encoded data (what the 435 # it'd be worth considering whether merging encoded data (what the
436 # repository usually sees) might be more useful. 436 # repository usually sees) might be more useful.
437 return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts) 437 return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts)
438 438
439 class ctxwriter(object):
440 def __init__(self, ctx):
441 self.ctx = ctx
442 self.text = ""
443
444 def write(self, text):
445 self.text += text
446
447 def close(self):
448 self.ctx.write(self.text, self.ctx.flags())
449
450 mode = opts.get('mode','merge') 439 mode = opts.get('mode','merge')
451 name_a, name_b, name_base = None, None, None 440 name_a, name_b, name_base = None, None, None
452 if mode != 'union': 441 if mode != 'union':
453 name_a, name_b, name_base = _picklabels([localctx.path(), 442 name_a, name_b, name_base = _picklabels([localctx.path(),
454 otherctx.path(), None], 443 otherctx.path(), None],
458 localtext = readctx(localctx) 447 localtext = readctx(localctx)
459 basetext = readctx(basectx) 448 basetext = readctx(basectx)
460 othertext = readctx(otherctx) 449 othertext = readctx(otherctx)
461 except error.Abort: 450 except error.Abort:
462 return 1 451 return 1
463
464 if opts.get('print'):
465 out = ui.fout
466 else:
467 out = ctxwriter(localctx)
468 452
469 m3 = Merge3Text(basetext, localtext, othertext) 453 m3 = Merge3Text(basetext, localtext, othertext)
470 extrakwargs = { 454 extrakwargs = {
471 "localorother": opts.get("localorother", None), 455 "localorother": opts.get("localorother", None),
472 'minimize': True, 456 'minimize': True,
477 extrakwargs['end_marker'] = None 461 extrakwargs['end_marker'] = None
478 elif name_base is not None: 462 elif name_base is not None:
479 extrakwargs['base_marker'] = '|||||||' 463 extrakwargs['base_marker'] = '|||||||'
480 extrakwargs['name_base'] = name_base 464 extrakwargs['name_base'] = name_base
481 extrakwargs['minimize'] = False 465 extrakwargs['minimize'] = False
466
467 mergedtext = ""
482 for line in m3.merge_lines(name_a=name_a, name_b=name_b, 468 for line in m3.merge_lines(name_a=name_a, name_b=name_b,
483 **pycompat.strkwargs(extrakwargs)): 469 **pycompat.strkwargs(extrakwargs)):
484 out.write(line) 470 if opts.get('print'):
471 ui.fout.write(line)
472 else:
473 mergedtext += line
485 474
486 if not opts.get('print'): 475 if not opts.get('print'):
487 out.close() 476 localctx.write(mergedtext, localctx.flags())
488 477
489 if m3.conflicts and not mode == 'union': 478 if m3.conflicts and not mode == 'union':
490 return 1 479 return 1