[PATCH] enable long/reserved paths on Windows (EXPERIMENTAL)

Adrian Buehlmann adrian at cadifra.com
Wed Jun 25 07:12:26 CDT 2008


On 24.06.2008 19:38, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1214326991 -7200
> # Node ID bee7843ebe514828cdd0e0041d51526ce236127f
> # Parent  af7b26b0f884d749ae8115256c009eea4c023378
> enable long/reserved paths on Windows (EXPERIMENTAL)
> 
> THIS PATCH IS EXPERIMENTAL ONLY, NOT INTENDED FOR INCLUSION INTO
> OFFICIAL MERCURIAL REPOS
> 

[snip]

> diff --git a/mercurial/osutil.py b/mercurial/osutil.py
> --- a/mercurial/osutil.py
> +++ b/mercurial/osutil.py
> @@ -1,4 +1,4 @@
> -import os, stat
> +import os, stat, util
>  
>  def _mode_to_kind(mode):
>      if stat.S_ISREG(mode): return stat.S_IFREG
> @@ -26,10 +26,10 @@
>      '''
>      result = []
>      prefix = path + os.sep
> -    names = os.listdir(path)
> +    names = os.listdir(util.longpath(path))
>      names.sort()
>      for fn in names:
> -        st = os.lstat(prefix + fn)
> +        st = os.lstat(util.longpath(prefix + fn))
>          if stat:
>              result.append((fn, _mode_to_kind(st.st_mode), st))
>          else:

I had to change this to:

diff --git a/mercurial/osutil.py b/mercurial/osutil.py
--- a/mercurial/osutil.py
+++ b/mercurial/osutil.py
@@ -1,4 +1,4 @@
-import os, stat
+import os, stat, util

 def _mode_to_kind(mode):
     if stat.S_ISREG(mode): return stat.S_IFREG
@@ -26,10 +26,11 @@
     '''
     result = []
     prefix = path + os.sep
-    names = os.listdir(path)
+    names = os.listdir(util.longpath(path)) # returns unicode strings on Windows!
     names.sort()
     for fn in names:
-        st = os.lstat(prefix + fn)
+        fn = str(fn) # convert to non-unicode string (needed on Windows)
+        st = os.lstat(util.longpath(prefix + fn))
         if stat:
             result.append((fn, _mode_to_kind(st.st_mode), st))
         else:

after having noticed that unicode strings had leaked into in-memory structures
of dirstate and manifest, which of course are not prepared to take unicode strings.

So the important thing I added is the line:

+        fn = str(fn) # convert to non-unicode string (needed on Windows)

I'm not sure if that's the correct way to get rid of the unicode strings.

Problem is that os.listdir(util.longpath(path)) returns unicode strings
because it uses the Windows long path api.


More information about the Mercurial-devel mailing list