win32mbcs: allow win32mbcs extension to be enabled on cygwin platform
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sun, 25 Dec 2011 20:32:48 +0900
changeset 15724 9e6a13c2aeb9
parent 15720 3bcfea777efc
child 15725 988409e44a76
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.
hgext/win32mbcs.py
--- a/hgext/win32mbcs.py	Sat Dec 24 00:52:06 2011 +0900
+++ 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