Mercurial > public > mercurial-scm > hg-stable
diff mercurial/filemerge.py @ 37002: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 |
line wrap: on
line diff
--- a/mercurial/filemerge.py Fri Jan 19 19:14:09 2018 -0800 +++ b/mercurial/filemerge.py Fri Jan 19 19:07:58 2018 -0800 @@ -10,6 +10,7 @@ import contextlib import os import re +import shutil import tempfile from .i18n import _ @@ -668,12 +669,23 @@ """Writes out `fco` and `fca` as temporary files, so an external merge tool may use them. """ + tmproot = None + tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix') + if tmprootprefix: + tmproot = tempfile.mkdtemp(prefix=tmprootprefix) + def temp(prefix, ctx): fullbase, ext = os.path.splitext(ctx.path()) - pre = "%s~%s." % (os.path.basename(fullbase), prefix) - (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext) + pre = "%s~%s" % (os.path.basename(fullbase), prefix) + if tmproot: + name = os.path.join(tmproot, pre) + if ext: + name += ext + f = open(name, r"wb") + else: + (fd, name) = tempfile.mkstemp(prefix=pre + '.', suffix=ext) + f = os.fdopen(fd, r"wb") data = repo.wwritedata(ctx.path(), ctx.data()) - f = os.fdopen(fd, r"wb") f.write(data) f.close() return name @@ -683,8 +695,11 @@ try: yield b, c finally: - util.unlink(b) - util.unlink(c) + if tmproot: + shutil.rmtree(tmproot) + else: + util.unlink(b) + util.unlink(c) def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): """perform a 3-way merge in the working directory