Mercurial > hg-stable
comparison mercurial/simplemerge.py @ 33850:b86fc43e4b73
simplemerge: write merge result to the localctx, if passed
Differential Revision: https://phab.mercurial-scm.org/D375
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Sun, 13 Aug 2017 22:46:03 -0700 |
parents | 8b91a4ff23ad |
children | aa6c290a77fa |
comparison
equal
deleted
inserted
replaced
33849:8b91a4ff23ad | 33850:b86fc43e4b73 |
---|---|
411 def simplemerge(ui, localfile, basefile, otherfile, | 411 def simplemerge(ui, localfile, basefile, otherfile, |
412 localctx=None, basectx=None, otherctx=None, repo=None, **opts): | 412 localctx=None, basectx=None, otherctx=None, repo=None, **opts): |
413 """Performs the simplemerge algorithm. | 413 """Performs the simplemerge algorithm. |
414 | 414 |
415 {local|base|other}ctx are optional. If passed, they (local/base/other) will | 415 {local|base|other}ctx are optional. If passed, they (local/base/other) will |
416 be read from. You should pass explicit labels in this mode since the default | 416 be read from and the merge result written to (local). You should pass |
417 is to use the file paths.""" | 417 explicit labels in this mode since the default is to use the file paths.""" |
418 def readfile(filename): | 418 def readfile(filename): |
419 f = open(filename, "rb") | 419 f = open(filename, "rb") |
420 text = f.read() | 420 text = f.read() |
421 f.close() | 421 f.close() |
422 return _verifytext(text, filename, ui, opts) | 422 return _verifytext(text, filename, ui, opts) |
431 # what would have been in the working copy). Since merges were run in | 431 # what would have been in the working copy). Since merges were run in |
432 # the working copy, and thus used post-filter data, we do the same to | 432 # the working copy, and thus used post-filter data, we do the same to |
433 # maintain behavior. | 433 # maintain behavior. |
434 return repo.wwritedata(ctx.path(), | 434 return repo.wwritedata(ctx.path(), |
435 _verifytext(ctx.data(), ctx.path(), ui, opts)) | 435 _verifytext(ctx.data(), ctx.path(), ui, opts)) |
436 | |
437 class ctxwriter(object): | |
438 def __init__(self, ctx): | |
439 self.ctx = ctx | |
440 self.text = "" | |
441 | |
442 def write(self, text): | |
443 self.text += text | |
444 | |
445 def close(self): | |
446 self.ctx.write(self.text, self.ctx.flags()) | |
436 | 447 |
437 mode = opts.get('mode','merge') | 448 mode = opts.get('mode','merge') |
438 if mode == 'union': | 449 if mode == 'union': |
439 name_a = None | 450 name_a = None |
440 name_b = None | 451 name_b = None |
458 basetext = readctx(basectx) if basectx else readfile(basefile) | 469 basetext = readctx(basectx) if basectx else readfile(basefile) |
459 othertext = readctx(otherctx) if otherctx else readfile(otherfile) | 470 othertext = readctx(otherctx) if otherctx else readfile(otherfile) |
460 except error.Abort: | 471 except error.Abort: |
461 return 1 | 472 return 1 |
462 | 473 |
463 localfile = os.path.realpath(localfile) | 474 if opts.get('print'): |
464 if not opts.get('print'): | 475 out = ui.fout |
476 elif localctx: | |
477 out = ctxwriter(localctx) | |
478 else: | |
479 localfile = os.path.realpath(localfile) | |
465 opener = vfsmod.vfs(os.path.dirname(localfile)) | 480 opener = vfsmod.vfs(os.path.dirname(localfile)) |
466 out = opener(os.path.basename(localfile), "w", atomictemp=True) | 481 out = opener(os.path.basename(localfile), "w", atomictemp=True) |
467 else: | |
468 out = ui.fout | |
469 | 482 |
470 m3 = Merge3Text(basetext, localtext, othertext) | 483 m3 = Merge3Text(basetext, localtext, othertext) |
471 extrakwargs = { | 484 extrakwargs = { |
472 "localorother": opts.get("localorother", None), | 485 "localorother": opts.get("localorother", None), |
473 'minimize': True, | 486 'minimize': True, |