Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 36998:3723b42ff953
filemerge: move temp file unlinks to _maketempfiles
Differential Revision: https://phab.mercurial-scm.org/D2887
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Fri, 19 Jan 2018 19:14:09 -0800 |
parents | 317382151ac3 |
children | e349ad5cbb71 |
comparison
equal
deleted
inserted
replaced
36997:44467a4d472f | 36998:3723b42ff953 |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import contextlib | |
10 import os | 11 import os |
11 import re | 12 import re |
12 import tempfile | 13 import tempfile |
13 | 14 |
14 from .i18n import _ | 15 from .i18n import _ |
508 repo.ui.warn(_('warning: %s cannot merge change/delete conflict ' | 509 repo.ui.warn(_('warning: %s cannot merge change/delete conflict ' |
509 'for %s\n') % (tool, fcd.path())) | 510 'for %s\n') % (tool, fcd.path())) |
510 return False, 1, None | 511 return False, 1, None |
511 unused, unused, unused, back = files | 512 unused, unused, unused, back = files |
512 localpath = _workingpath(repo, fcd) | 513 localpath = _workingpath(repo, fcd) |
513 basepath, otherpath = _maketempfiles(repo, fco, fca) | 514 with _maketempfiles(repo, fco, fca) as temppaths: |
514 try: | 515 basepath, otherpath = temppaths |
515 outpath = "" | 516 outpath = "" |
516 mylabel, otherlabel = labels[:2] | 517 mylabel, otherlabel = labels[:2] |
517 if len(labels) >= 3: | 518 if len(labels) >= 3: |
518 baselabel = labels[2] | 519 baselabel = labels[2] |
519 else: | 520 else: |
547 (tool, fcd.path())) | 548 (tool, fcd.path())) |
548 repo.ui.debug('launching merge tool: %s\n' % cmd) | 549 repo.ui.debug('launching merge tool: %s\n' % cmd) |
549 r = ui.system(cmd, cwd=repo.root, environ=env, blockedtag='mergetool') | 550 r = ui.system(cmd, cwd=repo.root, environ=env, blockedtag='mergetool') |
550 repo.ui.debug('merge tool returned: %d\n' % r) | 551 repo.ui.debug('merge tool returned: %d\n' % r) |
551 return True, r, False | 552 return True, r, False |
552 finally: | |
553 util.unlink(basepath) | |
554 util.unlink(otherpath) | |
555 | 553 |
556 def _formatconflictmarker(ctx, template, label, pad): | 554 def _formatconflictmarker(ctx, template, label, pad): |
557 """Applies the given template to the ctx, prefixed by the label. | 555 """Applies the given template to the ctx, prefixed by the label. |
558 | 556 |
559 Pad is the minimum width of the label prefix, so that multiple markers | 557 Pad is the minimum width of the label prefix, so that multiple markers |
663 util.copyfile(a, back) | 661 util.copyfile(a, back) |
664 # A arbitraryfilectx is returned, so we can run the same functions on | 662 # A arbitraryfilectx is returned, so we can run the same functions on |
665 # the backup context regardless of where it lives. | 663 # the backup context regardless of where it lives. |
666 return context.arbitraryfilectx(back, repo=repo) | 664 return context.arbitraryfilectx(back, repo=repo) |
667 | 665 |
666 @contextlib.contextmanager | |
668 def _maketempfiles(repo, fco, fca): | 667 def _maketempfiles(repo, fco, fca): |
669 """Writes out `fco` and `fca` as temporary files, so an external merge | 668 """Writes out `fco` and `fca` as temporary files, so an external merge |
670 tool may use them. | 669 tool may use them. |
671 """ | 670 """ |
672 def temp(prefix, ctx): | 671 def temp(prefix, ctx): |
679 f.close() | 678 f.close() |
680 return name | 679 return name |
681 | 680 |
682 b = temp("base", fca) | 681 b = temp("base", fca) |
683 c = temp("other", fco) | 682 c = temp("other", fco) |
684 | 683 try: |
685 return b, c | 684 yield b, c |
685 finally: | |
686 util.unlink(b) | |
687 util.unlink(c) | |
686 | 688 |
687 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): | 689 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): |
688 """perform a 3-way merge in the working directory | 690 """perform a 3-way merge in the working directory |
689 | 691 |
690 premerge = whether this is a premerge | 692 premerge = whether this is a premerge |