Mercurial > public > mercurial-scm > hg
comparison mercurial/simplemerge.py @ 33905:61b267a99fea
simplemerge: stop reading from, and writing to, files
We now use contexts first for everything and also pass them everywhere.
Differential Revision: https://phab.mercurial-scm.org/D380
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Thu, 24 Aug 2017 21:30:37 -0700 |
parents | 1915a5e809ca |
children | fa6309c5761d |
comparison
equal
deleted
inserted
replaced
33904:1915a5e809ca | 33905:61b267a99fea |
---|---|
16 # mbp: "you know that thing where cvs gives you conflict markers?" | 16 # mbp: "you know that thing where cvs gives you conflict markers?" |
17 # s: "i hate that." | 17 # s: "i hate that." |
18 | 18 |
19 from __future__ import absolute_import | 19 from __future__ import absolute_import |
20 | 20 |
21 import os | |
22 | |
23 from .i18n import _ | 21 from .i18n import _ |
24 from . import ( | 22 from . import ( |
25 error, | 23 error, |
26 mdiff, | 24 mdiff, |
27 pycompat, | 25 pycompat, |
28 util, | 26 util, |
29 vfs as vfsmod, | |
30 ) | 27 ) |
31 | 28 |
32 class CantReprocessAndShowBase(Exception): | 29 class CantReprocessAndShowBase(Exception): |
33 pass | 30 pass |
34 | 31 |
426 localctx=None, basectx=None, otherctx=None, repo=None, **opts): | 423 localctx=None, basectx=None, otherctx=None, repo=None, **opts): |
427 """Performs the simplemerge algorithm. | 424 """Performs the simplemerge algorithm. |
428 | 425 |
429 {local|base|other}ctx are optional. If passed, they (local/base/other) will | 426 {local|base|other}ctx are optional. If passed, they (local/base/other) will |
430 be read from and the merge result written to (local). You should pass | 427 be read from and the merge result written to (local). You should pass |
431 explicit labels in this mode since the default is to use the file paths.""" | 428 explicit labels in this mode since the default is to use the file paths. |
432 def readfile(filename): | 429 """ |
433 f = open(filename, "rb") | |
434 text = f.read() | |
435 f.close() | |
436 return _verifytext(text, filename, ui, opts) | |
437 | |
438 def readctx(ctx): | 430 def readctx(ctx): |
439 if not ctx: | 431 if not ctx: |
440 return None | 432 return None |
441 # Merges were always run in the working copy before, which means | 433 # Merges were always run in the working copy before, which means |
442 # they used decoded data, if the user defined any repository | 434 # they used decoded data, if the user defined any repository |
464 name_a, name_b, name_base = _picklabels([localctx.path(), | 456 name_a, name_b, name_base = _picklabels([localctx.path(), |
465 otherctx.path(), None], | 457 otherctx.path(), None], |
466 opts.get('label', [])) | 458 opts.get('label', [])) |
467 | 459 |
468 try: | 460 try: |
469 localtext = readctx(localctx) if localctx else readfile(localfile) | 461 localtext = readctx(localctx) |
470 basetext = readctx(basectx) if basectx else readfile(basefile) | 462 basetext = readctx(basectx) |
471 othertext = readctx(otherctx) if otherctx else readfile(otherfile) | 463 othertext = readctx(otherctx) |
472 except error.Abort: | 464 except error.Abort: |
473 return 1 | 465 return 1 |
474 | 466 |
475 if opts.get('print'): | 467 if opts.get('print'): |
476 out = ui.fout | 468 out = ui.fout |
477 elif localctx: | 469 else: |
478 out = ctxwriter(localctx) | 470 out = ctxwriter(localctx) |
479 else: | |
480 localfile = os.path.realpath(localfile) | |
481 opener = vfsmod.vfs(os.path.dirname(localfile)) | |
482 out = opener(os.path.basename(localfile), "w", atomictemp=True) | |
483 | 471 |
484 m3 = Merge3Text(basetext, localtext, othertext) | 472 m3 = Merge3Text(basetext, localtext, othertext) |
485 extrakwargs = { | 473 extrakwargs = { |
486 "localorother": opts.get("localorother", None), | 474 "localorother": opts.get("localorother", None), |
487 'minimize': True, | 475 'minimize': True, |