[PATCH] win32mbcs: Add configuration to specify path encoding

Shun-ichi Goto shunichi.goto at gmail.com
Mon Dec 7 04:19:30 CST 2009


# HG changeset patch
# User Shun-ichi GOTO <shunichi.goto at gmail.com>
# Date 1260181083 -32400
# Node ID 977e4ce1ccb37bc4be7741081b684eb678ea0705
# Parent  007d62ea19ebe4f20b81c3475da2acb04a7c3155
win32mbcs: Add configuration to specify path encoding.

Add win32mbcs.encoding configuration option to specify the encoding to
use instead of encoding.encoding.

This option is usefull for the users who want to write utf-8 log
message on non utf-8 path encoding environment.

diff -r 007d62ea19eb -r 977e4ce1ccb3 hgext/win32mbcs.py
--- a/hgext/win32mbcs.py	Mon Dec 07 16:46:31 2009 +0900
+++ b/hgext/win32mbcs.py	Mon Dec 07 19:18:03 2009 +0900
@@ -2,7 +2,7 @@
 #
 # Copyright (c) 2008 Shun-ichi Goto <shunichi.goto at gmail.com>
 #
-# Version: 0.2
+# Version: 0.3
 # Author:  Shun-ichi Goto <shunichi.goto at gmail.com>
 #
 # This software may be used and distributed according to the terms of the
@@ -33,22 +33,29 @@
 Note that there are some limitations on using this extension:
 
 - You should use single encoding in one repository.
-- You should set same encoding for the repository by locale or
-  HGENCODING.
 
-Path encoding conversion are done between Unicode and
-encoding.encoding which is decided by Mercurial from current locale
-setting or HGENCODING.
+
+By default, win32mbcs uses encoding.encoding decided by mercurial.
+You can specify the encoding by config option.
+
+ ex.)
+ [win32mbcs]
+ encoding = sjis
+
+It is usefull for the users who want to commit with utf-8 log message.
+
 '''
 
 import os, sys
 from mercurial.i18n import _
 from mercurial import util, encoding
 
+_encoding = None                                # see reposetup()
+
 def decode(arg):
     if isinstance(arg, str):
-        uarg = arg.decode(encoding.encoding)
-        if arg == uarg.encode(encoding.encoding):
+        uarg = arg.decode(_encoding)
+        if arg == uarg.encode(_encoding):
             return uarg
         raise UnicodeError("Not local encoding")
     elif isinstance(arg, tuple):
@@ -62,7 +69,7 @@
 
 def encode(arg):
     if isinstance(arg, unicode):
-        return arg.encode(encoding.encoding)
+        return arg.encode(_encoding)
     elif isinstance(arg, tuple):
         return tuple(map(encode, arg))
     elif isinstance(arg, list):
@@ -93,7 +100,7 @@
         return encode(func(*decode(args), **decode(kwds)))
     except UnicodeError:
         raise util.Abort(_("[win32mbcs] filename conversion failed with"
-                         " %s encoding\n") % (encoding.encoding))
+                         " %s encoding\n") % (_encoding))
 
 def wrapperforlistdir(func, args, kwds):
     # Ensure 'path' argument ends with os.sep to avoids
@@ -136,12 +143,14 @@
     if not os.path.supports_unicode_filenames:
         ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
         return
-
+    # determine encoding for filename
+    global _encoding
+    _encoding = ui.config('win32mbcs', 'encoding', encoding.encoding)
     # fake is only for relevant environment.
-    if encoding.encoding.lower() in problematic_encodings.split():
+    if _encoding.lower() in problematic_encodings.split():
         for f in funcs.split():
             wrapname(f, wrapper)
         wrapname("mercurial.osutil.listdir", wrapperforlistdir)
         ui.debug("[win32mbcs] activated with encoding: %s\n"
-                 % encoding.encoding)
+                 % _encoding)
 


More information about the Mercurial-devel mailing list