##// END OF EJS Templates
win32mbcs: Add configuration to specify path encoding...
Shun-ichi GOTO -
r10050:dd37f044 default
parent child Browse files
Show More
@@ -2,7 +2,7 b''
2 2 #
3 3 # Copyright (c) 2008 Shun-ichi Goto <shunichi.goto@gmail.com>
4 4 #
5 # Version: 0.2
5 # Version: 0.3
6 6 # Author: Shun-ichi Goto <shunichi.goto@gmail.com>
7 7 #
8 8 # This software may be used and distributed according to the terms of the
@@ -33,22 +33,29 b' This extension is not needed for:'
33 33 Note that there are some limitations on using this extension:
34 34
35 35 - You should use single encoding in one repository.
36 - You should set same encoding for the repository by locale or
37 HGENCODING.
36
37
38 By default, win32mbcs uses encoding.encoding decided by mercurial.
39 You can specify the encoding by config option.
38 40
39 Path encoding conversion are done between Unicode and
40 encoding.encoding which is decided by Mercurial from current locale
41 setting or HGENCODING.
41 ex.)
42 [win32mbcs]
43 encoding = sjis
44
45 It is usefull for the users who want to commit with utf-8 log message.
46
42 47 '''
43 48
44 49 import os, sys
45 50 from mercurial.i18n import _
46 51 from mercurial import util, encoding
47 52
53 _encoding = None # see reposetup()
54
48 55 def decode(arg):
49 56 if isinstance(arg, str):
50 uarg = arg.decode(encoding.encoding)
51 if arg == uarg.encode(encoding.encoding):
57 uarg = arg.decode(_encoding)
58 if arg == uarg.encode(_encoding):
52 59 return uarg
53 60 raise UnicodeError("Not local encoding")
54 61 elif isinstance(arg, tuple):
@@ -62,7 +69,7 b' def decode(arg):'
62 69
63 70 def encode(arg):
64 71 if isinstance(arg, unicode):
65 return arg.encode(encoding.encoding)
72 return arg.encode(_encoding)
66 73 elif isinstance(arg, tuple):
67 74 return tuple(map(encode, arg))
68 75 elif isinstance(arg, list):
@@ -93,7 +100,7 b' def wrapper(func, args, kwds):'
93 100 return encode(func(*decode(args), **decode(kwds)))
94 101 except UnicodeError:
95 102 raise util.Abort(_("[win32mbcs] filename conversion failed with"
96 " %s encoding\n") % (encoding.encoding))
103 " %s encoding\n") % (_encoding))
97 104
98 105 def wrapperforlistdir(func, args, kwds):
99 106 # Ensure 'path' argument ends with os.sep to avoids
@@ -136,12 +143,14 b' def reposetup(ui, repo):'
136 143 if not os.path.supports_unicode_filenames:
137 144 ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
138 145 return
139
146 # determine encoding for filename
147 global _encoding
148 _encoding = ui.config('win32mbcs', 'encoding', encoding.encoding)
140 149 # fake is only for relevant environment.
141 if encoding.encoding.lower() in problematic_encodings.split():
150 if _encoding.lower() in problematic_encodings.split():
142 151 for f in funcs.split():
143 152 wrapname(f, wrapper)
144 153 wrapname("mercurial.osutil.listdir", wrapperforlistdir)
145 154 ui.debug("[win32mbcs] activated with encoding: %s\n"
146 % encoding.encoding)
155 % _encoding)
147 156
General Comments 0
You need to be logged in to leave comments. Login now