34 To use this extension, enable the extension in .hg/hgrc or ~/.hgrc: |
34 To use this extension, enable the extension in .hg/hgrc or ~/.hgrc: |
35 |
35 |
36 [extensions] |
36 [extensions] |
37 hgext.win32mbcs = |
37 hgext.win32mbcs = |
38 |
38 |
39 Path encoding conversion are done between unicode and util._encoding |
39 Path encoding conversion are done between unicode and encoding.encoding |
40 which is decided by mercurial from current locale setting or HGENCODING. |
40 which is decided by mercurial from current locale setting or HGENCODING. |
41 |
41 |
42 """ |
42 """ |
43 |
43 |
44 import os |
44 import os |
45 from mercurial.i18n import _ |
45 from mercurial.i18n import _ |
46 from mercurial import util |
46 from mercurial import util, encoding |
47 |
47 |
48 def decode(arg): |
48 def decode(arg): |
49 if isinstance(arg, str): |
49 if isinstance(arg, str): |
50 uarg = arg.decode(util._encoding) |
50 uarg = arg.decode(encoding.encoding) |
51 if arg == uarg.encode(util._encoding): |
51 if arg == uarg.encode(encoding.encoding): |
52 return uarg |
52 return uarg |
53 raise UnicodeError("Not local encoding") |
53 raise UnicodeError("Not local encoding") |
54 elif isinstance(arg, tuple): |
54 elif isinstance(arg, tuple): |
55 return tuple(map(decode, arg)) |
55 return tuple(map(decode, arg)) |
56 elif isinstance(arg, list): |
56 elif isinstance(arg, list): |
57 return map(decode, arg) |
57 return map(decode, arg) |
58 return arg |
58 return arg |
59 |
59 |
60 def encode(arg): |
60 def encode(arg): |
61 if isinstance(arg, unicode): |
61 if isinstance(arg, unicode): |
62 return arg.encode(util._encoding) |
62 return arg.encode(encoding.encoding) |
63 elif isinstance(arg, tuple): |
63 elif isinstance(arg, tuple): |
64 return tuple(map(encode, arg)) |
64 return tuple(map(encode, arg)) |
65 elif isinstance(arg, list): |
65 elif isinstance(arg, list): |
66 return map(encode, arg) |
66 return map(encode, arg) |
67 return arg |
67 return arg |
74 |
74 |
75 try: |
75 try: |
76 # convert arguments to unicode, call func, then convert back |
76 # convert arguments to unicode, call func, then convert back |
77 return encode(func(*decode(args))) |
77 return encode(func(*decode(args))) |
78 except UnicodeError: |
78 except UnicodeError: |
79 # If not encoded with util._encoding, report it then |
79 # If not encoded with encoding.encoding, report it then |
80 # continue with calling original function. |
80 # continue with calling original function. |
81 raise util.Abort(_("[win32mbcs] filename conversion fail with" |
81 raise util.Abort(_("[win32mbcs] filename conversion fail with" |
82 " %s encoding\n") % (util._encoding)) |
82 " %s encoding\n") % (encoding.encoding)) |
83 |
83 |
84 def wrapname(name): |
84 def wrapname(name): |
85 idx = name.rfind('.') |
85 idx = name.rfind('.') |
86 module = name[:idx] |
86 module = name[:idx] |
87 name = name[idx+1:] |
87 name = name[idx+1:] |
113 if not os.path.supports_unicode_filenames: |
113 if not os.path.supports_unicode_filenames: |
114 ui.warn(_("[win32mbcs] cannot activate on this platform.\n")) |
114 ui.warn(_("[win32mbcs] cannot activate on this platform.\n")) |
115 return |
115 return |
116 |
116 |
117 # fake is only for relevant environment. |
117 # fake is only for relevant environment. |
118 if util._encoding.lower() in problematic_encodings.split(): |
118 if encoding.encoding.lower() in problematic_encodings.split(): |
119 for f in funcs.split(): |
119 for f in funcs.split(): |
120 wrapname(f) |
120 wrapname(f) |
121 ui.debug(_("[win32mbcs] activated with encoding: %s\n") % util._encoding) |
121 ui.debug(_("[win32mbcs] activated with encoding: %s\n") |
|
122 % encoding.encoding) |
122 |
123 |