# HG changeset patch
# User Mads Kiilerich <mad...@unity3d.com>
# Date 1479383976 -3600
#      Thu Nov 17 12:59:36 2016 +0100
# Node ID 5409e0c5e6c0764e802360a3912f7719885ba2b5
# Parent  23e2868f6dfd50d4d7ca3e0748cb62bcf4354a52
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
@@ -219,9 +219,16 @@ def checklink(path):
     # mktemp is not racy because symlink creation will fail if the
     # file already exists
     while True:
-        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)
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to