hardlink: duplicate hardlink detection for copying files and directories
authorJun Wu <quark@fb.com>
Wed, 29 Mar 2017 12:26:46 -0700
changeset 31719 456efd1b51fd
parent 31718 bf64449b2779
child 31720 dea2a17cbfd0
hardlink: duplicate hardlink detection for copying files and directories A later patch will change one of them so they diverge.
mercurial/util.py
--- 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)