Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 36999:e349ad5cbb71
filemerge: use a single temp dir instead of temp files
This can help to remove the clutter from UIs that display just the filenames;
instead of seeing foo~local.C9ru9r.txt and foo~base.2DMV22.txt (in the /tmp
directory on most platforms), we create a single new directory and use that,
producing filenames like /tmp/hgmerge.C9ru9r/foo~local.txt.
Differential Revision: https://phab.mercurial-scm.org/D2888
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Fri, 19 Jan 2018 19:07:58 -0800 |
parents | 3723b42ff953 |
children | 1e30a26a65d0 |
comparison
equal
deleted
inserted
replaced
36998:3723b42ff953 | 36999:e349ad5cbb71 |
---|---|
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import contextlib | 10 import contextlib |
11 import os | 11 import os |
12 import re | 12 import re |
13 import shutil | |
13 import tempfile | 14 import tempfile |
14 | 15 |
15 from .i18n import _ | 16 from .i18n import _ |
16 from .node import nullid, short | 17 from .node import nullid, short |
17 | 18 |
666 @contextlib.contextmanager | 667 @contextlib.contextmanager |
667 def _maketempfiles(repo, fco, fca): | 668 def _maketempfiles(repo, fco, fca): |
668 """Writes out `fco` and `fca` as temporary files, so an external merge | 669 """Writes out `fco` and `fca` as temporary files, so an external merge |
669 tool may use them. | 670 tool may use them. |
670 """ | 671 """ |
672 tmproot = None | |
673 tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix') | |
674 if tmprootprefix: | |
675 tmproot = tempfile.mkdtemp(prefix=tmprootprefix) | |
676 | |
671 def temp(prefix, ctx): | 677 def temp(prefix, ctx): |
672 fullbase, ext = os.path.splitext(ctx.path()) | 678 fullbase, ext = os.path.splitext(ctx.path()) |
673 pre = "%s~%s." % (os.path.basename(fullbase), prefix) | 679 pre = "%s~%s" % (os.path.basename(fullbase), prefix) |
674 (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext) | 680 if tmproot: |
681 name = os.path.join(tmproot, pre) | |
682 if ext: | |
683 name += ext | |
684 f = open(name, r"wb") | |
685 else: | |
686 (fd, name) = tempfile.mkstemp(prefix=pre + '.', suffix=ext) | |
687 f = os.fdopen(fd, r"wb") | |
675 data = repo.wwritedata(ctx.path(), ctx.data()) | 688 data = repo.wwritedata(ctx.path(), ctx.data()) |
676 f = os.fdopen(fd, r"wb") | |
677 f.write(data) | 689 f.write(data) |
678 f.close() | 690 f.close() |
679 return name | 691 return name |
680 | 692 |
681 b = temp("base", fca) | 693 b = temp("base", fca) |
682 c = temp("other", fco) | 694 c = temp("other", fco) |
683 try: | 695 try: |
684 yield b, c | 696 yield b, c |
685 finally: | 697 finally: |
686 util.unlink(b) | 698 if tmproot: |
687 util.unlink(c) | 699 shutil.rmtree(tmproot) |
700 else: | |
701 util.unlink(b) | |
702 util.unlink(c) | |
688 | 703 |
689 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): | 704 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): |
690 """perform a 3-way merge in the working directory | 705 """perform a 3-way merge in the working directory |
691 | 706 |
692 premerge = whether this is a premerge | 707 premerge = whether this is a premerge |