[PATCH 3 of 4 V2] util: enable hardlink for copyfile

Jun Wu quark at fb.com
Tue Mar 21 22:00:55 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 e960baabf0da65e84e99466d4be9acaa4b9b91b2
# Parent  fef923fbdbaece1d3ea237f96088e5086ee6367c
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r e960baabf0da
util: enable hardlink for copyfile

This patch removes the global variable "allowhardlinks" that disables
hardlink in all cases, so hardlink gets enabled if the filesystem type is
whitelisted.

Third party extensions wanting to enable hardlink support unconditionally
can replace "_hardlinkfswhitelist.__contains__".

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1057,9 +1057,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([
@@ -1097,5 +1092,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