[PATCH 1 of 4 STABLE] win32mbcs: allow win32mbcs extension to be enabled on cygwin platform

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Dec 25 05:38:07 CST 2011


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1324812768 -32400
# Branch stable
# Node ID f26c74b9cc9f393e7aacec50c3260c8042b995db
# Parent  32a6e00e4cfe84573b9d4dc71155d0dc23b75faf
win32mbcs: allow win32mbcs extension to be enabled on cygwin platform

this patch allows win32mbcs extension to be enabled on cygwin platform
for problematic character encodings.

on recent cygwin platform, even though
"os.path.supports_unicode_filenames" is False, "os.listdir()" and
other path manipulation functions can return the result correctly
decoded in unicode for invocations with unicode arguments, if locale
is configured properly.

existing code to check "os.path.supports_unicode_filenames" is kept to
prevent win32mbcs from being enabled on unexpected platform.

diff -r 32a6e00e4cfe -r f26c74b9cc9f hgext/win32mbcs.py
--- a/hgext/win32mbcs.py	Tue Dec 20 14:11:14 2011 -0600
+++ b/hgext/win32mbcs.py	Sun Dec 25 20:32:48 2011 +0900
@@ -127,11 +127,14 @@
 # NOTE: os.path.dirname() and os.path.basename() are safe because
 #       they use result of os.path.split()
 funcs = '''os.path.join os.path.split os.path.splitext
- os.path.splitunc os.path.normpath os.makedirs
+ os.path.normpath os.makedirs
  mercurial.util.endswithsep mercurial.util.splitpath mercurial.util.checkcase
  mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath
  mercurial.util.checkwinfilename mercurial.util.checkosfilename'''
 
+# List of Windows specific functions to be wrapped.
+winfuncs = '''os.path.splitunc'''
+
 # codec and alias names of sjis and big5 to be faked.
 problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs
  hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis
@@ -140,7 +143,8 @@
 
 def extsetup(ui):
     # TODO: decide use of config section for this extension
-    if not os.path.supports_unicode_filenames:
+    if ((not os.path.supports_unicode_filenames) and
+        (sys.platform != 'cygwin')):
         ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
         return
     # determine encoding for filename
@@ -150,6 +154,9 @@
     if _encoding.lower() in problematic_encodings.split():
         for f in funcs.split():
             wrapname(f, wrapper)
+        if os.name == 'nt':
+            for f in winfuncs.split():
+                wrapname(f, wrapper)
         wrapname("mercurial.osutil.listdir", wrapperforlistdir)
         # Check sys.args manually instead of using ui.debug() because
         # command line options is not yet applied when


More information about the Mercurial-devel mailing list