Show More
@@ -49,6 +49,9 b' def decode(arg):' | |||||
49 | return tuple(map(decode, arg)) |
|
49 | return tuple(map(decode, arg)) | |
50 | elif isinstance(arg, list): |
|
50 | elif isinstance(arg, list): | |
51 | return map(decode, arg) |
|
51 | return map(decode, arg) | |
|
52 | elif isinstance(arg, dict): | |||
|
53 | for k, v in arg.items(): | |||
|
54 | arg[k] = decode(v) | |||
52 | return arg |
|
55 | return arg | |
53 |
|
56 | |||
54 | def encode(arg): |
|
57 | def encode(arg): | |
@@ -58,29 +61,50 b' def encode(arg):' | |||||
58 | return tuple(map(encode, arg)) |
|
61 | return tuple(map(encode, arg)) | |
59 | elif isinstance(arg, list): |
|
62 | elif isinstance(arg, list): | |
60 | return map(encode, arg) |
|
63 | return map(encode, arg) | |
|
64 | elif isinstance(arg, dict): | |||
|
65 | for k, v in arg.items(): | |||
|
66 | arg[k] = encode(v) | |||
61 | return arg |
|
67 | return arg | |
62 |
|
68 | |||
63 | def wrapper(func, args): |
|
69 | def appendsep(s): | |
|
70 | # ensure the path ends with os.sep, appending it if necessary. | |||
|
71 | try: | |||
|
72 | us = decode(s) | |||
|
73 | except UnicodeError: | |||
|
74 | us = s | |||
|
75 | if us and us[-1] not in ':/\\': | |||
|
76 | s += os.sep | |||
|
77 | return s | |||
|
78 | ||||
|
79 | def wrapper(func, args, kwds): | |||
64 | # check argument is unicode, then call original |
|
80 | # check argument is unicode, then call original | |
65 | for arg in args: |
|
81 | for arg in args: | |
66 | if isinstance(arg, unicode): |
|
82 | if isinstance(arg, unicode): | |
67 | return func(*args) |
|
83 | return func(*args, **kwds) | |
68 |
|
84 | |||
69 | try: |
|
85 | try: | |
70 | # convert arguments to unicode, call func, then convert back |
|
86 | # convert arguments to unicode, call func, then convert back | |
71 | return encode(func(*decode(args))) |
|
87 | return encode(func(*decode(args), **decode(kwds))) | |
72 | except UnicodeError: |
|
88 | except UnicodeError: | |
73 | # If not encoded with encoding.encoding, report it then |
|
89 | raise util.Abort(_("[win32mbcs] filename conversion failed with" | |
74 | # continue with calling original function. |
|
|||
75 | raise util.Abort(_("[win32mbcs] filename conversion fail with" |
|
|||
76 | " %s encoding\n") % (encoding.encoding)) |
|
90 | " %s encoding\n") % (encoding.encoding)) | |
77 |
|
91 | |||
78 | def wrapname(name): |
|
92 | def wrapperforlistdir(func, args, kwds): | |
|
93 | # Ensure 'path' argument ends with os.sep to avoids | |||
|
94 | # misinterpreting last 0x5c of MBCS 2nd byte as path separator. | |||
|
95 | if args: | |||
|
96 | args = list(args) | |||
|
97 | args[0] = appendsep(args[0]) | |||
|
98 | if kwds.has_key('path'): | |||
|
99 | kwds['path'] = appendsep(kwds['path']) | |||
|
100 | return func(*args, **kwds) | |||
|
101 | ||||
|
102 | def wrapname(name, wrapper): | |||
79 | module, name = name.rsplit('.', 1) |
|
103 | module, name = name.rsplit('.', 1) | |
80 | module = sys.modules[module] |
|
104 | module = sys.modules[module] | |
81 | func = getattr(module, name) |
|
105 | func = getattr(module, name) | |
82 | def f(*args): |
|
106 | def f(*args, **kwds): | |
83 | return wrapper(func, args) |
|
107 | return wrapper(func, args, kwds) | |
84 | try: |
|
108 | try: | |
85 | f.__name__ = func.__name__ # fail with python23 |
|
109 | f.__name__ = func.__name__ # fail with python23 | |
86 | except Exception: |
|
110 | except Exception: | |
@@ -110,7 +134,8 b' def reposetup(ui, repo):' | |||||
110 | # fake is only for relevant environment. |
|
134 | # fake is only for relevant environment. | |
111 | if encoding.encoding.lower() in problematic_encodings.split(): |
|
135 | if encoding.encoding.lower() in problematic_encodings.split(): | |
112 | for f in funcs.split(): |
|
136 | for f in funcs.split(): | |
113 | wrapname(f) |
|
137 | wrapname(f, wrapper) | |
|
138 | wrapname("mercurial.osutil.listdir", wrapperforlistdir) | |||
114 | ui.debug(_("[win32mbcs] activated with encoding: %s\n") |
|
139 | ui.debug(_("[win32mbcs] activated with encoding: %s\n") | |
115 | % encoding.encoding) |
|
140 | % encoding.encoding) | |
116 |
|
141 |
@@ -284,16 +284,17 b' class fncachestore(basicstore):' | |||||
284 | self.pathjoiner = pathjoiner |
|
284 | self.pathjoiner = pathjoiner | |
285 | self.path = self.pathjoiner(path, 'store') |
|
285 | self.path = self.pathjoiner(path, 'store') | |
286 | self.createmode = _calcmode(self.path) |
|
286 | self.createmode = _calcmode(self.path) | |
287 |
|
|
287 | op = opener(self.path) | |
288 |
|
|
288 | op.createmode = self.createmode | |
289 |
|
|
289 | fnc = fncache(op) | |
|
290 | self.fncache = fnc | |||
290 |
|
291 | |||
291 | def fncacheopener(path, mode='r', *args, **kw): |
|
292 | def fncacheopener(path, mode='r', *args, **kw): | |
292 | if (mode not in ('r', 'rb') |
|
293 | if (mode not in ('r', 'rb') | |
293 | and path.startswith('data/') |
|
294 | and path.startswith('data/') | |
294 |
and path not in |
|
295 | and path not in fnc): | |
295 |
|
|
296 | fnc.add(path) | |
296 |
return |
|
297 | return op(hybridencode(path), mode, *args, **kw) | |
297 | self.opener = fncacheopener |
|
298 | self.opener = fncacheopener | |
298 |
|
299 | |||
299 | def join(self, f): |
|
300 | def join(self, f): |
General Comments 0
You need to be logged in to leave comments.
Login now