comparison mercurial/simplemerge.py @ 46100:a771ffc378a8

simplemerge: write output only once it's complete `simplemerge()` can write either to `ui.fout` or to the file context (for in-memory merge). This patch simplifies the code a bit by making it build the output the same way regardless of where it's written, and then writes the whole output at once. I don't think it will be a problem that we don't output anything until the whole file is merged even if the file is large. Differential Revision: https://phab.mercurial-scm.org/D9550
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 09 Dec 2020 00:00:19 -0800
parents fd75e5c53ec3
children bdc2bf68f19e
comparison
equal deleted inserted replaced
46099:fd75e5c53ec3 46100:a771ffc378a8
497 elif name_base is not None: 497 elif name_base is not None:
498 extrakwargs[b'base_marker'] = b'|||||||' 498 extrakwargs[b'base_marker'] = b'|||||||'
499 extrakwargs[b'name_base'] = name_base 499 extrakwargs[b'name_base'] = name_base
500 extrakwargs[b'minimize'] = False 500 extrakwargs[b'minimize'] = False
501 501
502 lines = [] 502 lines = m3.merge_lines(
503 for line in m3.merge_lines(
504 name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs) 503 name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs)
505 ): 504 )
506 if opts.get('print'):
507 ui.fout.write(line)
508 else:
509 lines.append(line)
510 505
511 # merge flags if necessary 506 # merge flags if necessary
512 flags = localctx.flags() 507 flags = localctx.flags()
513 localflags = set(pycompat.iterbytestr(flags)) 508 localflags = set(pycompat.iterbytestr(flags))
514 otherflags = set(pycompat.iterbytestr(otherctx.flags())) 509 otherflags = set(pycompat.iterbytestr(otherctx.flags()))
516 baseflags = set(pycompat.iterbytestr(basectx.flags())) 511 baseflags = set(pycompat.iterbytestr(basectx.flags()))
517 commonflags = localflags & otherflags 512 commonflags = localflags & otherflags
518 addedflags = (localflags ^ otherflags) - baseflags 513 addedflags = (localflags ^ otherflags) - baseflags
519 flags = b''.join(sorted(commonflags | addedflags)) 514 flags = b''.join(sorted(commonflags | addedflags))
520 515
521 if not opts.get('print'): 516 mergedtext = b''.join(lines)
522 mergedtext = b''.join(lines) 517 if opts.get('print'):
518 ui.fout.write(mergedtext)
519 else:
523 localctx.write(mergedtext, flags) 520 localctx.write(mergedtext, flags)
524 521
525 if m3.conflicts and not mode == b'union': 522 if m3.conflicts and not mode == b'union':
526 return 1 523 return 1