[PATCH 7 of 7 V3] util: enable hardlink for copyfile

Jun Wu quark at fb.com
Sun Mar 12 05:23:56 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1489309403 28800
#      Sun Mar 12 01:03:23 2017 -0800
# Node ID 9da40a9e54c419490a2ff23b9dda7acc109f81cd
# Parent  de28b62236a7d47a896bc4aba2bd95dcd8defc87
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 9da40a9e54c4
util: enable hardlink for copyfile

Because why not, if we are sure that the filesystem has good hardlink
support (and we are - see "posix: implement a method to get filesystem type
for Linux").

This patch removes the global variable "allowhardlinks" added by "util: add
allowhardlinks module variable". Third party extensions wanting to enable
hardlink support unconditionally can replace "_hardlinkfswhitelist".

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1058,9 +1058,4 @@ def checksignature(func):
     return check
 
-# Hardlinks are problematic on CIFS, do not allow hardlinks
-# until we find a way to work around it cleanly (issue4546).
-# This is a variable so extensions can opt-in to using them.
-allowhardlinks = False
-
 # a whilelist of known filesystems where hardlink works reliably
 _hardlinkfswhitelist = set([
@@ -1094,5 +1089,5 @@ def copyfile(src, dest, hardlink=False, 
         if fstype not in _hardlinkfswhitelist:
             hardlink = False
-    if allowhardlinks and hardlink:
+    if hardlink:
         try:
             oslink(src, dest)
diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks-whitelisted.t
copy from tests/test-hardlinks.t
copy to tests/test-hardlinks-whitelisted.t
--- a/tests/test-hardlinks.t
+++ b/tests/test-hardlinks-whitelisted.t
@@ -1,3 +1,9 @@
 #require hardlink
+#require hardlink-whitelisted
+
+This test is similar to test-hardlinks.t, but will only run on some filesystems
+that we are sure to have known good hardlink supports (see issue4546 for an
+example where the filesystem claims hardlink support but is actually
+problematic).
 
   $ cat > nlinks.py <<EOF
@@ -167,5 +173,5 @@ Push to repo r1 should break up most har
   1 r2/.hg/store/data/d1/f2.i
   2 r2/.hg/store/data/f1.i
-  1 r2/.hg/store/fncache
+  2 r2/.hg/store/fncache
 
   $ hg -R r2 verify
@@ -192,5 +198,5 @@ Committing a change to f1 in r1 must bre
   1 r2/.hg/store/data/d1/f2.i
   1 r2/.hg/store/data/f1.i
-  1 r2/.hg/store/fncache
+  2 r2/.hg/store/fncache
 
 
@@ -234,9 +240,9 @@ r4 has hardlinks in the working dir (not
   2 r4/.hg/store/undo.backupfiles
   2 r4/.hg/store/undo.phaseroots
-  2 r4/.hg/undo.backup.dirstate
+  4 r4/.hg/undo.backup.dirstate
   2 r4/.hg/undo.bookmarks
   2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
-  2 r4/.hg/undo.dirstate
+  4 r4/.hg/undo.dirstate
   2 r4/d1/data1
   2 r4/d1/f2
@@ -273,9 +279,9 @@ Update back to revision 11 in r4 should 
   2 r4/.hg/store/undo.backupfiles
   2 r4/.hg/store/undo.phaseroots
-  2 r4/.hg/undo.backup.dirstate
+  4 r4/.hg/undo.backup.dirstate
   2 r4/.hg/undo.bookmarks
   2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
-  2 r4/.hg/undo.dirstate
+  4 r4/.hg/undo.dirstate
   2 r4/d1/data1
   2 r4/d1/f2
diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t
--- a/tests/test-hardlinks.t
+++ b/tests/test-hardlinks.t
@@ -167,5 +167,5 @@ Push to repo r1 should break up most har
   1 r2/.hg/store/data/d1/f2.i
   2 r2/.hg/store/data/f1.i
-  1 r2/.hg/store/fncache
+  [12] r2/\.hg/store/fncache (re)
 
   $ hg -R r2 verify
@@ -192,5 +192,5 @@ Committing a change to f1 in r1 must bre
   1 r2/.hg/store/data/d1/f2.i
   1 r2/.hg/store/data/f1.i
-  1 r2/.hg/store/fncache
+  [12] r2/\.hg/store/fncache (re)
 
 
@@ -234,9 +234,9 @@ r4 has hardlinks in the working dir (not
   2 r4/.hg/store/undo.backupfiles
   2 r4/.hg/store/undo.phaseroots
-  2 r4/.hg/undo.backup.dirstate
+  [24] r4/\.hg/undo\.backup\.dirstate (re)
   2 r4/.hg/undo.bookmarks
   2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
-  2 r4/.hg/undo.dirstate
+  [24] r4/\.hg/undo\.dirstate (re)
   2 r4/d1/data1
   2 r4/d1/f2
@@ -273,9 +273,9 @@ Update back to revision 11 in r4 should 
   2 r4/.hg/store/undo.backupfiles
   2 r4/.hg/store/undo.phaseroots
-  2 r4/.hg/undo.backup.dirstate
+  [24] r4/\.hg/undo\.backup\.dirstate (re)
   2 r4/.hg/undo.bookmarks
   2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
-  2 r4/.hg/undo.dirstate
+  [24] r4/\.hg/undo\.dirstate (re)
   2 r4/d1/data1
   2 r4/d1/f2


More information about the Mercurial-devel mailing list