Commits

Katsunori FUJIWARA committed 2482f06

add initial contents

Comments (0)

Files changed (3)

+^\.hg
+^\.mq
+syntax: glob
+status
+guards
+win32mbcs-on-all-platform.patch

win32mbcs-on-all-platform.patch

+# HG changeset patch
+# Parent f36f11f2bfce0c5fb1581e0074eba2ef88f359e7
+win32mbcs: available win32mbcs on all platform to run tests 
+
+After applying this patch on the revision which you want to test, you
+can run test enabling win32mbcs always by:
+
+    make TESTFLAGS="--extra-config-opt extensions.win32mbcs=" tests
+
+This patch changes points below to enable win32mbcs on all platform:
+
+  - add "ascii" and "utf-8" to "problematic_encodings" list to enable
+    win32mbcs for any encodings
+
+  - avoid "os.path.supports_unicode_filenames" and "sys.platform"
+    checking
+
+  - skip wrapping function if target module is not loaded yet: on some
+    posix environments, "mercurial.osutil" is not yet loaded when
+    extsetup() of win32mbcs is executed.
+
+In addition to them, this patch adds "uniguard()" wrapping to examine
+whether target function is invoked unexpectedly with unicode object or
+not.
+
+In wrapping target functions of win32mbcs, "mercurial.util.fspath()"
+is the only function which may invokes other internal mercurial APIs.
+And such callees of "mercurial.util.fspath()" are limited to
+"mercurial.encoding.lower", "mercurial.encoding.upper" and
+"mercurial.util.normcase", now (@2012/09/30).
+
+This patch guards them not to be invoked with unicode object
+arguments.
+
+diff -r f36f11f2bfce hgext/win32mbcs.py
+--- a/hgext/win32mbcs.py	Thu Sep 27 15:50:14 2012 -0500
++++ b/hgext/win32mbcs.py	Sun Sep 30 02:13:46 2012 +0900
+@@ -45,6 +45,24 @@
+ It is useful for the users who want to commit with UTF-8 log message.
+ '''
+ 
++def uniguard(name):
++    module, name = name.rsplit('.', 1)
++    module = sys.modules[module]
++    func = getattr(module, name)
++    def guard(*args, **kwds):
++        for arg in args:
++            if isinstance(arg, unicode):
++                raise ValueError('unexpected unicode object')
++        for k, v in kwds.items():
++            if isinstance(v, unicode):
++                raise ValueError('unexpected unicode object')
++        return func(*args, **kwds)
++    try:
++        f.__name__ = func.__name__                # fail with python23
++    except Exception:
++        pass
++    setattr(module, name, guard)
++
+ import os, sys
+ from mercurial.i18n import _
+ from mercurial import util, encoding
+@@ -114,6 +132,8 @@
+ 
+ def wrapname(name, wrapper):
+     module, name = name.rsplit('.', 1)
++    if module not in sys.modules:
++        return
+     module = sys.modules[module]
+     func = getattr(module, name)
+     def f(*args, **kwds):
+@@ -138,16 +158,18 @@
+ 
+ # codec and alias names of sjis and big5 to be faked.
+ problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs
++ ascii utf-8
+  hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis
+  sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004
+  shift_jisx0213 shiftjisx0213 sjisx0213 s_jisx0213 950 cp950 ms950 '''
+ 
+ def extsetup(ui):
++    # guard before win32mbcs wrapping
++    uniguard("mercurial.encoding.lower")
++    uniguard("mercurial.encoding.upper")
++    uniguard("mercurial.util.normcase")
++
+     # TODO: decide use of config section for this extension
+-    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
+     global _encoding
+     _encoding = ui.config('win32mbcs', 'encoding', encoding.encoding)
+@@ -163,5 +185,4 @@
+         # command line options is not yet applied when
+         # extensions.loadall() is called.
+         if '--debug' in sys.argv:
+-            ui.write("[win32mbcs] activated with encoding: %s\n"
+-                     % _encoding)
++            pass