D851: [RFC] setup: increase MAX_PATH limit on Windows 10 Anniversary Update

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sat Sep 30 09:46:04 UTC 2017


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  As documented at
  https://msdn.microsoft.com/en-gb/library/windows/desktop/aa365247(v=vs.85).aspx
  system settings or per-application settings can now opt in to increasing
  the length of MAX_PATH, removing the 260 character restriction. This
  impacts the following API calls:
  
  CreateDirectoryW, CreateDirectoryExW, GetCurrentDirectoryW,
  RemoveDirectoryW, SetCurrentDirectoryW, CopyFileW, CopyFile2,
  CopyFileExW, CreateFileW, CreateFile2, CreateHardLinkW,
  CreateSymbolicLinkW, DeleteFileW, FindFirstFileW, FindFirstFileExW,
  FindNextFileW, GetFileAttributesW, GetFileAttributesExW,
  SetFileAttributesW, GetFullPathNameW, GetLongPathNameW, MoveFileW,
  MoveFileExW, MoveFileWithProgressW, ReplaceFileW, SearchPathW,
  FindFirstFileNameW, FindNextFileNameW, FindFirstStreamW,
  FindNextStreamW, GetCompressedFileSizeW, GetFinalPathNameByHandleW.
  
  Adding an application manifest to hg.exe will activate this setting
  and possibly eliminate some 260 character path length limitations
  in Mercurial without having to convert all paths to absolute and use
  the "\\?\" prefix, which was previously the only supported mechanism
  for using longer paths.
  
  I HAVE NOT YET TESTED THIS PATCH.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D851

AFFECTED FILES
  setup.py

CHANGE DETAILS

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -514,6 +514,16 @@
             f.write('docs = ')
             f.write(out)
 
+# ws2:longPathAware increases MAX_PATH on Windows 10 Anniversary Edition and
+# newer to larger than its default of 260.
+HGEXE_MANIFEST = '''
+<application xmlns="urn:schemas-microsoft-com:asm.v3">
+    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
+        <ws2:longPathAware>true</ws2:longPathAware>
+    </windowsSettings>
+</application>
+'''.strip()
+
 class buildhgexe(build_ext):
     description = 'compile hg.exe from mercurial/exewrapper.c'
 
@@ -556,11 +566,20 @@
             f.write('#define HGPYTHONLIB "%s"\n' % pythonlib)
         objects = self.compiler.compile(['mercurial/exewrapper.c'],
                                          output_dir=self.build_temp)
-        dir = os.path.dirname(self.get_ext_fullpath('dummy'))
-        target = os.path.join(dir, 'hg')
-        self.compiler.link_executable(objects, target,
-                                      libraries=[],
-                                      output_dir=self.build_temp)
+
+        try:
+            fd, manifestpath = tempfile.mkstemp('.manifest')
+            fd.write(HGEXE_MANIFEST)
+            fd.close()
+
+            dir = os.path.dirname(self.get_ext_fullpath('dummy'))
+            target = os.path.join(dir, 'hg')
+
+            self.compiler.link_executable(objects, target,
+                libraries=[], output_dir=self.build_temp,
+                extra_postargs=['/MANIFESTFILE:%s' % manifestpath])
+        finally:
+            os.unlink(manifestpath)
 
     @property
     def hgexepath(self):



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list