Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 31577:e7a02e9ad162
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__".
author | Jun Wu <quark@fb.com> |
---|---|
date | Sun, 12 Mar 2017 01:03:23 -0800 |
parents | e506e461c7a9 |
children | ae02cc1f5369 |
comparison
equal
deleted
inserted
replaced
31576:07f0cddb0594 | 31577:e7a02e9ad162 |
---|---|
1053 raise error.SignatureError | 1053 raise error.SignatureError |
1054 raise | 1054 raise |
1055 | 1055 |
1056 return check | 1056 return check |
1057 | 1057 |
1058 # Hardlinks are problematic on CIFS, do not allow hardlinks | |
1059 # until we find a way to work around it cleanly (issue4546). | |
1060 # This is a variable so extensions can opt-in to using them. | |
1061 allowhardlinks = False | |
1062 | |
1063 # a whilelist of known filesystems where hardlink works reliably | 1058 # a whilelist of known filesystems where hardlink works reliably |
1064 _hardlinkfswhitelist = set([ | 1059 _hardlinkfswhitelist = set([ |
1065 'btrfs', | 1060 'btrfs', |
1066 'ext2', | 1061 'ext2', |
1067 'ext3', | 1062 'ext3', |
1093 # unless we are confident that dest is on a whitelisted filesystem. | 1088 # unless we are confident that dest is on a whitelisted filesystem. |
1094 destdir = os.path.dirname(dest) | 1089 destdir = os.path.dirname(dest) |
1095 fstype = getattr(osutil, 'getfstype', lambda x: None)(destdir) | 1090 fstype = getattr(osutil, 'getfstype', lambda x: None)(destdir) |
1096 if fstype not in _hardlinkfswhitelist: | 1091 if fstype not in _hardlinkfswhitelist: |
1097 hardlink = False | 1092 hardlink = False |
1098 if allowhardlinks and hardlink: | 1093 if hardlink: |
1099 try: | 1094 try: |
1100 oslink(src, dest) | 1095 oslink(src, dest) |
1101 return | 1096 return |
1102 except (IOError, OSError): | 1097 except (IOError, OSError): |
1103 pass # fall back to normal copy | 1098 pass # fall back to normal copy |