[PATCH 4 of 5 rfc] posix: move checklink test file to .hg/cache

Mads Kiilerich mads at kiilerich.com
Sat Oct 24 11:32:02 CDT 2015


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1445704208 -7200
#      Sat Oct 24 18:30:08 2015 +0200
# Branch stable
# Node ID 3a6d970e2d2f86b51b6ad0223a4da1a3a3e19bc9
# Parent  5921bcc389073dfdb4a44284db5ee00bcbb0c499
posix: move checklink test file to .hg/cache

This avoids unnecessary churn in the working directory.

It is not necessarily a fully valid assumption that .hg/cache is on the same
filesystem as the working directory, but I think it is an acceptable
approximation. It could also be the case that different parts of the working
directory is on different mount points so checking in the root folder could
also be wrong.

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -214,9 +214,15 @@ def checklink(path):
     """check whether the given path is on a symlink-capable filesystem"""
     # mktemp is not racy because symlink creation will fail if the
     # file already exists
-    name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
+    cachedir = os.path.join(path, '.hg', 'cache')
+    if os.path.isdir(cachedir):
+        checkdir = cachedir
+    else:
+        checkdir = path
+        cachedir = None
+    name = tempfile.mktemp(dir=checkdir, prefix='checklink-')
     try:
-        fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
+        fd = tempfile.NamedTemporaryFile(dir=checkdir, prefix='hg-checklink-')
         try:
             os.symlink(os.path.basename(fd.name), name)
             os.unlink(name)


More information about the Mercurial-devel mailing list