changeset 23899:4e451d1359de

copyfile: allow optional hardlinking Some code paths use 'copyfiles' (full tree) for a single file to take advantage of the best-effort-hard-linking parameter. We add similar parameter and logic to 'copyfile' (single file) for this purpose. The single file version have the advantage to overwrite the destination file if it exists.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 05 Jan 2015 12:39:09 -0800
parents b21c2e0ee8a3
children 5eb3541f907e
files mercurial/util.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Thu Jan 15 16:51:13 2015 -0800
+++ b/mercurial/util.py	Mon Jan 05 12:39:09 2015 -0800
@@ -716,10 +716,16 @@
 
     return check
 
-def copyfile(src, dest):
+def copyfile(src, dest, hardlink=False):
     "copy a file, preserving mode and atime/mtime"
     if os.path.lexists(dest):
         unlink(dest)
+    if hardlink:
+        try:
+            oslink(src, dest)
+            return
+        except (IOError, OSError):
+            pass # fall back to normal copy
     if os.path.islink(src):
         os.symlink(os.readlink(src), dest)
     else: