[PATCH 1 of 2] copyfile: allow optional hardlinking
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Sat Jan 17 00:47:43 UTC 2015
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1420490349 28800
# Mon Jan 05 12:39:09 2015 -0800
# Node ID 28ab98266efd7717443607d4ecb30d036ef03452
# Parent 81349f4b47f4c793873290852808ff095ab24c00
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.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -714,14 +714,20 @@ def checksignature(func):
raise error.SignatureError
raise
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:
try:
shutil.copyfile(src, dest)
More information about the Mercurial-devel
mailing list