Mercurial > hg
comparison mercurial/scmutil.py @ 37084:f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
This might conflict with other patches floating around, sorry.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 22 Mar 2018 21:56:20 +0900 |
parents | a00c38b33047 |
children | 7f025c9b7865 |
comparison
equal
deleted
inserted
replaced
37083:f99d64e8a4e4 | 37084:f0b6fbea00cf |
---|---|
37 revsetlang, | 37 revsetlang, |
38 similar, | 38 similar, |
39 url, | 39 url, |
40 util, | 40 util, |
41 vfs, | 41 vfs, |
42 ) | |
43 | |
44 from .utils import ( | |
45 stringutil, | |
42 ) | 46 ) |
43 | 47 |
44 if pycompat.iswindows: | 48 if pycompat.iswindows: |
45 from . import scmwindows as scmplatform | 49 from . import scmwindows as scmplatform |
46 else: | 50 else: |
161 if inst.errno == errno.ETIMEDOUT: | 165 if inst.errno == errno.ETIMEDOUT: |
162 reason = _('timed out waiting for lock held by %r') % inst.locker | 166 reason = _('timed out waiting for lock held by %r') % inst.locker |
163 else: | 167 else: |
164 reason = _('lock held by %r') % inst.locker | 168 reason = _('lock held by %r') % inst.locker |
165 ui.warn(_("abort: %s: %s\n") | 169 ui.warn(_("abort: %s: %s\n") |
166 % (inst.desc or util.forcebytestr(inst.filename), reason)) | 170 % (inst.desc or stringutil.forcebytestr(inst.filename), reason)) |
167 if not inst.locker: | 171 if not inst.locker: |
168 ui.warn(_("(lock might be very busy)\n")) | 172 ui.warn(_("(lock might be very busy)\n")) |
169 except error.LockUnavailable as inst: | 173 except error.LockUnavailable as inst: |
170 ui.warn(_("abort: could not lock %s: %s\n") % | 174 ui.warn(_("abort: could not lock %s: %s\n") % |
171 (inst.desc or util.forcebytestr(inst.filename), | 175 (inst.desc or stringutil.forcebytestr(inst.filename), |
172 encoding.strtolocal(inst.strerror))) | 176 encoding.strtolocal(inst.strerror))) |
173 except error.OutOfBandError as inst: | 177 except error.OutOfBandError as inst: |
174 if inst.args: | 178 if inst.args: |
175 msg = _("abort: remote error:\n") | 179 msg = _("abort: remote error:\n") |
176 else: | 180 else: |
192 if not isinstance(msg, bytes): | 196 if not isinstance(msg, bytes): |
193 ui.warn(" %r\n" % (msg,)) | 197 ui.warn(" %r\n" % (msg,)) |
194 elif not msg: | 198 elif not msg: |
195 ui.warn(_(" empty string\n")) | 199 ui.warn(_(" empty string\n")) |
196 else: | 200 else: |
197 ui.warn("\n%r\n" % util.ellipsis(msg)) | 201 ui.warn("\n%r\n" % stringutil.ellipsis(msg)) |
198 except error.CensoredNodeError as inst: | 202 except error.CensoredNodeError as inst: |
199 ui.warn(_("abort: file censored %s!\n") % inst) | 203 ui.warn(_("abort: file censored %s!\n") % inst) |
200 except error.RevlogError as inst: | 204 except error.RevlogError as inst: |
201 ui.warn(_("abort: %s!\n") % inst) | 205 ui.warn(_("abort: %s!\n") % inst) |
202 except error.InterventionRequired as inst: | 206 except error.InterventionRequired as inst: |
209 except error.Abort as inst: | 213 except error.Abort as inst: |
210 ui.warn(_("abort: %s\n") % inst) | 214 ui.warn(_("abort: %s\n") % inst) |
211 if inst.hint: | 215 if inst.hint: |
212 ui.warn(_("(%s)\n") % inst.hint) | 216 ui.warn(_("(%s)\n") % inst.hint) |
213 except ImportError as inst: | 217 except ImportError as inst: |
214 ui.warn(_("abort: %s!\n") % util.forcebytestr(inst)) | 218 ui.warn(_("abort: %s!\n") % stringutil.forcebytestr(inst)) |
215 m = util.forcebytestr(inst).split()[-1] | 219 m = stringutil.forcebytestr(inst).split()[-1] |
216 if m in "mpatch bdiff".split(): | 220 if m in "mpatch bdiff".split(): |
217 ui.warn(_("(did you forget to compile extensions?)\n")) | 221 ui.warn(_("(did you forget to compile extensions?)\n")) |
218 elif m in "zlib".split(): | 222 elif m in "zlib".split(): |
219 ui.warn(_("(is your Python install correct?)\n")) | 223 ui.warn(_("(is your Python install correct?)\n")) |
220 except IOError as inst: | 224 except IOError as inst: |
221 if util.safehasattr(inst, "code"): | 225 if util.safehasattr(inst, "code"): |
222 ui.warn(_("abort: %s\n") % util.forcebytestr(inst)) | 226 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst)) |
223 elif util.safehasattr(inst, "reason"): | 227 elif util.safehasattr(inst, "reason"): |
224 try: # usually it is in the form (errno, strerror) | 228 try: # usually it is in the form (errno, strerror) |
225 reason = inst.reason.args[1] | 229 reason = inst.reason.args[1] |
226 except (AttributeError, IndexError): | 230 except (AttributeError, IndexError): |
227 # it might be anything, for example a string | 231 # it might be anything, for example a string |
235 pass | 239 pass |
236 elif getattr(inst, "strerror", None): | 240 elif getattr(inst, "strerror", None): |
237 if getattr(inst, "filename", None): | 241 if getattr(inst, "filename", None): |
238 ui.warn(_("abort: %s: %s\n") % ( | 242 ui.warn(_("abort: %s: %s\n") % ( |
239 encoding.strtolocal(inst.strerror), | 243 encoding.strtolocal(inst.strerror), |
240 util.forcebytestr(inst.filename))) | 244 stringutil.forcebytestr(inst.filename))) |
241 else: | 245 else: |
242 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) | 246 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
243 else: | 247 else: |
244 raise | 248 raise |
245 except OSError as inst: | 249 except OSError as inst: |
246 if getattr(inst, "filename", None) is not None: | 250 if getattr(inst, "filename", None) is not None: |
247 ui.warn(_("abort: %s: '%s'\n") % ( | 251 ui.warn(_("abort: %s: '%s'\n") % ( |
248 encoding.strtolocal(inst.strerror), | 252 encoding.strtolocal(inst.strerror), |
249 util.forcebytestr(inst.filename))) | 253 stringutil.forcebytestr(inst.filename))) |
250 else: | 254 else: |
251 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) | 255 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
252 except MemoryError: | 256 except MemoryError: |
253 ui.warn(_("abort: out of memory\n")) | 257 ui.warn(_("abort: out of memory\n")) |
254 except SystemExit as inst: | 258 except SystemExit as inst: |
255 # Commands shouldn't sys.exit directly, but give a return code. | 259 # Commands shouldn't sys.exit directly, but give a return code. |
256 # Just in case catch this and and pass exit code to caller. | 260 # Just in case catch this and and pass exit code to caller. |
257 return inst.code | 261 return inst.code |
258 except socket.error as inst: | 262 except socket.error as inst: |
259 ui.warn(_("abort: %s\n") % util.forcebytestr(inst.args[-1])) | 263 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst.args[-1])) |
260 | 264 |
261 return -1 | 265 return -1 |
262 | 266 |
263 def checknewlabel(repo, lbl, kind): | 267 def checknewlabel(repo, lbl, kind): |
264 # Do not use the "kind" parameter in ui output. | 268 # Do not use the "kind" parameter in ui output. |
297 def checkportabilityalert(ui): | 301 def checkportabilityalert(ui): |
298 '''check if the user's config requests nothing, a warning, or abort for | 302 '''check if the user's config requests nothing, a warning, or abort for |
299 non-portable filenames''' | 303 non-portable filenames''' |
300 val = ui.config('ui', 'portablefilenames') | 304 val = ui.config('ui', 'portablefilenames') |
301 lval = val.lower() | 305 lval = val.lower() |
302 bval = util.parsebool(val) | 306 bval = stringutil.parsebool(val) |
303 abort = pycompat.iswindows or lval == 'abort' | 307 abort = pycompat.iswindows or lval == 'abort' |
304 warn = bval or lval == 'warn' | 308 warn = bval or lval == 'warn' |
305 if bval is None and not (warn or abort or lval == 'ignore'): | 309 if bval is None and not (warn or abort or lval == 'ignore'): |
306 raise error.ConfigError( | 310 raise error.ConfigError( |
307 _("ui.portablefilenames value is invalid ('%s')") % val) | 311 _("ui.portablefilenames value is invalid ('%s')") % val) |