##// 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 # Copyright (c) 2008 Shun-ichi Goto <shunichi.goto@gmail.com>
3 # Copyright (c) 2008 Shun-ichi Goto <shunichi.goto@gmail.com>
4 #
4 #
5 # Version: 0.2
5 # Version: 0.3
6 # Author: Shun-ichi Goto <shunichi.goto@gmail.com>
6 # Author: Shun-ichi Goto <shunichi.goto@gmail.com>
7 #
7 #
8 # This software may be used and distributed according to the terms of the
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 Note that there are some limitations on using this extension:
33 Note that there are some limitations on using this extension:
34
34
35 - You should use single encoding in one repository.
35 - You should use single encoding in one repository.
36 - You should set same encoding for the repository by locale or
36
37 HGENCODING.
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
41 ex.)
40 encoding.encoding which is decided by Mercurial from current locale
42 [win32mbcs]
41 setting or HGENCODING.
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 import os, sys
49 import os, sys
45 from mercurial.i18n import _
50 from mercurial.i18n import _
46 from mercurial import util, encoding
51 from mercurial import util, encoding
47
52
53 _encoding = None # see reposetup()
54
48 def decode(arg):
55 def decode(arg):
49 if isinstance(arg, str):
56 if isinstance(arg, str):
50 uarg = arg.decode(encoding.encoding)
57 uarg = arg.decode(_encoding)
51 if arg == uarg.encode(encoding.encoding):
58 if arg == uarg.encode(_encoding):
52 return uarg
59 return uarg
53 raise UnicodeError("Not local encoding")
60 raise UnicodeError("Not local encoding")
54 elif isinstance(arg, tuple):
61 elif isinstance(arg, tuple):
@@ -62,7 +69,7 b' def decode(arg):'
62
69
63 def encode(arg):
70 def encode(arg):
64 if isinstance(arg, unicode):
71 if isinstance(arg, unicode):
65 return arg.encode(encoding.encoding)
72 return arg.encode(_encoding)
66 elif isinstance(arg, tuple):
73 elif isinstance(arg, tuple):
67 return tuple(map(encode, arg))
74 return tuple(map(encode, arg))
68 elif isinstance(arg, list):
75 elif isinstance(arg, list):
@@ -93,7 +100,7 b' def wrapper(func, args, kwds):'
93 return encode(func(*decode(args), **decode(kwds)))
100 return encode(func(*decode(args), **decode(kwds)))
94 except UnicodeError:
101 except UnicodeError:
95 raise util.Abort(_("[win32mbcs] filename conversion failed with"
102 raise util.Abort(_("[win32mbcs] filename conversion failed with"
96 " %s encoding\n") % (encoding.encoding))
103 " %s encoding\n") % (_encoding))
97
104
98 def wrapperforlistdir(func, args, kwds):
105 def wrapperforlistdir(func, args, kwds):
99 # Ensure 'path' argument ends with os.sep to avoids
106 # Ensure 'path' argument ends with os.sep to avoids
@@ -136,12 +143,14 b' def reposetup(ui, repo):'
136 if not os.path.supports_unicode_filenames:
143 if not os.path.supports_unicode_filenames:
137 ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
144 ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
138 return
145 return
139
146 # determine encoding for filename
147 global _encoding
148 _encoding = ui.config('win32mbcs', 'encoding', encoding.encoding)
140 # fake is only for relevant environment.
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 for f in funcs.split():
151 for f in funcs.split():
143 wrapname(f, wrapper)
152 wrapname(f, wrapper)
144 wrapname("mercurial.osutil.listdir", wrapperforlistdir)
153 wrapname("mercurial.osutil.listdir", wrapperforlistdir)
145 ui.debug("[win32mbcs] activated with encoding: %s\n"
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