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