Show More
@@ -69,6 +69,16 b' def encode(arg):' | |||||
69 | arg[k] = encode(v) |
|
69 | arg[k] = encode(v) | |
70 | return arg |
|
70 | return arg | |
71 |
|
71 | |||
|
72 | def appendsep(s): | |||
|
73 | # ensure the path ends with os.sep, appending it if necessary. | |||
|
74 | try: | |||
|
75 | us = decode(s) | |||
|
76 | except UnicodeError: | |||
|
77 | us = s | |||
|
78 | if us and us[-1] not in ':/\\': | |||
|
79 | s += os.sep | |||
|
80 | return s | |||
|
81 | ||||
72 | def wrapper(func, args, kwds): |
|
82 | def wrapper(func, args, kwds): | |
73 | # check argument is unicode, then call original |
|
83 | # check argument is unicode, then call original | |
74 | for arg in args: |
|
84 | for arg in args: | |
@@ -79,12 +89,20 b' def wrapper(func, args, kwds):' | |||||
79 | # convert arguments to unicode, call func, then convert back |
|
89 | # convert arguments to unicode, call func, then convert back | |
80 | return encode(func(*decode(args), **decode(kwds))) |
|
90 | return encode(func(*decode(args), **decode(kwds))) | |
81 | except UnicodeError: |
|
91 | except UnicodeError: | |
82 | # If not encoded with encoding.encoding, report it then |
|
92 | raise util.Abort(_("[win32mbcs] filename conversion failed with" | |
83 | # continue with calling original function. |
|
|||
84 | raise util.Abort(_("[win32mbcs] filename conversion fail with" |
|
|||
85 | " %s encoding\n") % (encoding.encoding)) |
|
93 | " %s encoding\n") % (encoding.encoding)) | |
86 |
|
94 | |||
87 | def wrapname(name): |
|
95 | def wrapperforlistdir(func, args, kwds): | |
|
96 | # Ensure 'path' argument ends with os.sep to avoids | |||
|
97 | # misinterpreting last 0x5c of MBCS 2nd byte as path separator. | |||
|
98 | if args: | |||
|
99 | args = list(args) | |||
|
100 | args[0] = appendsep(args[0]) | |||
|
101 | if kwds.has_key('path'): | |||
|
102 | kwds['path'] = appendsep(kwds['path']) | |||
|
103 | return func(*args, **kwds) | |||
|
104 | ||||
|
105 | def wrapname(name, wrapper): | |||
88 | module, name = name.rsplit('.', 1) |
|
106 | module, name = name.rsplit('.', 1) | |
89 | module = sys.modules[module] |
|
107 | module = sys.modules[module] | |
90 | func = getattr(module, name) |
|
108 | func = getattr(module, name) | |
@@ -119,7 +137,8 b' def reposetup(ui, repo):' | |||||
119 | # fake is only for relevant environment. |
|
137 | # fake is only for relevant environment. | |
120 | if encoding.encoding.lower() in problematic_encodings.split(): |
|
138 | if encoding.encoding.lower() in problematic_encodings.split(): | |
121 | for f in funcs.split(): |
|
139 | for f in funcs.split(): | |
122 | wrapname(f) |
|
140 | wrapname(f, wrapper) | |
|
141 | wrapname("mercurial.osutil.listdir", wrapperforlistdir) | |||
123 | ui.debug(_("[win32mbcs] activated with encoding: %s\n") |
|
142 | ui.debug(_("[win32mbcs] activated with encoding: %s\n") | |
124 | % encoding.encoding) |
|
143 | % encoding.encoding) | |
125 |
|
144 |
General Comments 0
You need to be logged in to leave comments.
Login now