changeset 31719:456efd1b51fd

hardlink: duplicate hardlink detection for copying files and directories A later patch will change one of them so they diverge.
author Jun Wu <quark@fb.com>
date Wed, 29 Mar 2017 12:26:46 -0700
parents bf64449b2779
children dea2a17cbfd0
files mercurial/util.py
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Wed Mar 29 12:21:15 2017 -0700
+++ b/mercurial/util.py	Wed Mar 29 12:26:46 2017 -0700
@@ -1126,14 +1126,13 @@
     """Copy a directory tree using hardlinks if possible."""
     num = 0
 
-    if hardlink is None:
-        hardlink = (os.stat(src).st_dev ==
-                    os.stat(os.path.dirname(dst)).st_dev)
-
     gettopic = lambda: hardlink and _('linking') or _('copying')
-    topic = gettopic()
 
     if os.path.isdir(src):
+        if hardlink is None:
+            hardlink = (os.stat(src).st_dev ==
+                        os.stat(os.path.dirname(dst)).st_dev)
+        topic = gettopic()
         os.mkdir(dst)
         for name, kind in osutil.listdir(src):
             srcname = os.path.join(src, name)
@@ -1144,6 +1143,11 @@
             hardlink, n = copyfiles(srcname, dstname, hardlink, progress=nprog)
             num += n
     else:
+        if hardlink is None:
+            hardlink = (os.stat(src).st_dev ==
+                        os.stat(os.path.dirname(dst)).st_dev)
+        topic = gettopic()
+
         if hardlink:
             try:
                 oslink(src, dst)