Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 38768:afc4ad706f9c
dispatch: making all hg abortions be output with a specific label
This allows abortions to be highlighted specially and separately
from warnings - for instance, red is a reasonable color for when hg
aborts, but is overly dramatic for most warnings produced elsewhere.
Differential Revision: https://phab.mercurial-scm.org/D3967
author | Rodrigo Damazio Bovendorp <rdamazio@google.com> |
---|---|
date | Thu, 19 Jul 2018 23:22:05 -0700 |
parents | f8cbff2184d7 |
children | e7aa113b14f7 |
comparison
equal
deleted
inserted
replaced
38767:eb2945f0a4a1 | 38768:afc4ad706f9c |
---|---|
167 except error.LockHeld as inst: | 167 except error.LockHeld as inst: |
168 if inst.errno == errno.ETIMEDOUT: | 168 if inst.errno == errno.ETIMEDOUT: |
169 reason = _('timed out waiting for lock held by %r') % inst.locker | 169 reason = _('timed out waiting for lock held by %r') % inst.locker |
170 else: | 170 else: |
171 reason = _('lock held by %r') % inst.locker | 171 reason = _('lock held by %r') % inst.locker |
172 ui.warn(_("abort: %s: %s\n") | 172 ui.error(_("abort: %s: %s\n") % ( |
173 % (inst.desc or stringutil.forcebytestr(inst.filename), reason)) | 173 inst.desc or stringutil.forcebytestr(inst.filename), reason)) |
174 if not inst.locker: | 174 if not inst.locker: |
175 ui.warn(_("(lock might be very busy)\n")) | 175 ui.error(_("(lock might be very busy)\n")) |
176 except error.LockUnavailable as inst: | 176 except error.LockUnavailable as inst: |
177 ui.warn(_("abort: could not lock %s: %s\n") % | 177 ui.error(_("abort: could not lock %s: %s\n") % |
178 (inst.desc or stringutil.forcebytestr(inst.filename), | 178 (inst.desc or stringutil.forcebytestr(inst.filename), |
179 encoding.strtolocal(inst.strerror))) | 179 encoding.strtolocal(inst.strerror))) |
180 except error.OutOfBandError as inst: | 180 except error.OutOfBandError as inst: |
181 if inst.args: | 181 if inst.args: |
182 msg = _("abort: remote error:\n") | 182 msg = _("abort: remote error:\n") |
183 else: | 183 else: |
184 msg = _("abort: remote error\n") | 184 msg = _("abort: remote error\n") |
185 ui.warn(msg) | 185 ui.error(msg) |
186 if inst.args: | 186 if inst.args: |
187 ui.warn(''.join(inst.args)) | 187 ui.error(''.join(inst.args)) |
188 if inst.hint: | 188 if inst.hint: |
189 ui.warn('(%s)\n' % inst.hint) | 189 ui.error('(%s)\n' % inst.hint) |
190 except error.RepoError as inst: | 190 except error.RepoError as inst: |
191 ui.warn(_("abort: %s!\n") % inst) | 191 ui.error(_("abort: %s!\n") % inst) |
192 if inst.hint: | 192 if inst.hint: |
193 ui.warn(_("(%s)\n") % inst.hint) | 193 ui.error(_("(%s)\n") % inst.hint) |
194 except error.ResponseError as inst: | 194 except error.ResponseError as inst: |
195 ui.warn(_("abort: %s") % inst.args[0]) | 195 ui.error(_("abort: %s") % inst.args[0]) |
196 msg = inst.args[1] | 196 msg = inst.args[1] |
197 if isinstance(msg, type(u'')): | 197 if isinstance(msg, type(u'')): |
198 msg = pycompat.sysbytes(msg) | 198 msg = pycompat.sysbytes(msg) |
199 if not isinstance(msg, bytes): | 199 if not isinstance(msg, bytes): |
200 ui.warn(" %r\n" % (msg,)) | 200 ui.error(" %r\n" % (msg,)) |
201 elif not msg: | 201 elif not msg: |
202 ui.warn(_(" empty string\n")) | 202 ui.error(_(" empty string\n")) |
203 else: | 203 else: |
204 ui.warn("\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg))) | 204 ui.error("\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg))) |
205 except error.CensoredNodeError as inst: | 205 except error.CensoredNodeError as inst: |
206 ui.warn(_("abort: file censored %s!\n") % inst) | 206 ui.error(_("abort: file censored %s!\n") % inst) |
207 except error.RevlogError as inst: | 207 except error.RevlogError as inst: |
208 ui.warn(_("abort: %s!\n") % inst) | 208 ui.error(_("abort: %s!\n") % inst) |
209 except error.InterventionRequired as inst: | 209 except error.InterventionRequired as inst: |
210 ui.warn("%s\n" % inst) | 210 ui.error("%s\n" % inst) |
211 if inst.hint: | 211 if inst.hint: |
212 ui.warn(_("(%s)\n") % inst.hint) | 212 ui.error(_("(%s)\n") % inst.hint) |
213 return 1 | 213 return 1 |
214 except error.WdirUnsupported: | 214 except error.WdirUnsupported: |
215 ui.warn(_("abort: working directory revision cannot be specified\n")) | 215 ui.error(_("abort: working directory revision cannot be specified\n")) |
216 except error.Abort as inst: | 216 except error.Abort as inst: |
217 ui.warn(_("abort: %s\n") % inst) | 217 ui.error(_("abort: %s\n") % inst) |
218 if inst.hint: | 218 if inst.hint: |
219 ui.warn(_("(%s)\n") % inst.hint) | 219 ui.error(_("(%s)\n") % inst.hint) |
220 except ImportError as inst: | 220 except ImportError as inst: |
221 ui.warn(_("abort: %s!\n") % stringutil.forcebytestr(inst)) | 221 ui.error(_("abort: %s!\n") % stringutil.forcebytestr(inst)) |
222 m = stringutil.forcebytestr(inst).split()[-1] | 222 m = stringutil.forcebytestr(inst).split()[-1] |
223 if m in "mpatch bdiff".split(): | 223 if m in "mpatch bdiff".split(): |
224 ui.warn(_("(did you forget to compile extensions?)\n")) | 224 ui.error(_("(did you forget to compile extensions?)\n")) |
225 elif m in "zlib".split(): | 225 elif m in "zlib".split(): |
226 ui.warn(_("(is your Python install correct?)\n")) | 226 ui.error(_("(is your Python install correct?)\n")) |
227 except IOError as inst: | 227 except IOError as inst: |
228 if util.safehasattr(inst, "code"): | 228 if util.safehasattr(inst, "code"): |
229 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst)) | 229 ui.error(_("abort: %s\n") % stringutil.forcebytestr(inst)) |
230 elif util.safehasattr(inst, "reason"): | 230 elif util.safehasattr(inst, "reason"): |
231 try: # usually it is in the form (errno, strerror) | 231 try: # usually it is in the form (errno, strerror) |
232 reason = inst.reason.args[1] | 232 reason = inst.reason.args[1] |
233 except (AttributeError, IndexError): | 233 except (AttributeError, IndexError): |
234 # it might be anything, for example a string | 234 # it might be anything, for example a string |
235 reason = inst.reason | 235 reason = inst.reason |
236 if isinstance(reason, pycompat.unicode): | 236 if isinstance(reason, pycompat.unicode): |
237 # SSLError of Python 2.7.9 contains a unicode | 237 # SSLError of Python 2.7.9 contains a unicode |
238 reason = encoding.unitolocal(reason) | 238 reason = encoding.unitolocal(reason) |
239 ui.warn(_("abort: error: %s\n") % reason) | 239 ui.error(_("abort: error: %s\n") % reason) |
240 elif (util.safehasattr(inst, "args") | 240 elif (util.safehasattr(inst, "args") |
241 and inst.args and inst.args[0] == errno.EPIPE): | 241 and inst.args and inst.args[0] == errno.EPIPE): |
242 pass | 242 pass |
243 elif getattr(inst, "strerror", None): | 243 elif getattr(inst, "strerror", None): |
244 if getattr(inst, "filename", None): | 244 if getattr(inst, "filename", None): |
245 ui.warn(_("abort: %s: %s\n") % ( | 245 ui.error(_("abort: %s: %s\n") % ( |
246 encoding.strtolocal(inst.strerror), | 246 encoding.strtolocal(inst.strerror), |
247 stringutil.forcebytestr(inst.filename))) | 247 stringutil.forcebytestr(inst.filename))) |
248 else: | 248 else: |
249 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) | 249 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
250 else: | 250 else: |
251 raise | 251 raise |
252 except OSError as inst: | 252 except OSError as inst: |
253 if getattr(inst, "filename", None) is not None: | 253 if getattr(inst, "filename", None) is not None: |
254 ui.warn(_("abort: %s: '%s'\n") % ( | 254 ui.error(_("abort: %s: '%s'\n") % ( |
255 encoding.strtolocal(inst.strerror), | 255 encoding.strtolocal(inst.strerror), |
256 stringutil.forcebytestr(inst.filename))) | 256 stringutil.forcebytestr(inst.filename))) |
257 else: | 257 else: |
258 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) | 258 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror)) |
259 except MemoryError: | 259 except MemoryError: |
260 ui.warn(_("abort: out of memory\n")) | 260 ui.error(_("abort: out of memory\n")) |
261 except SystemExit as inst: | 261 except SystemExit as inst: |
262 # Commands shouldn't sys.exit directly, but give a return code. | 262 # Commands shouldn't sys.exit directly, but give a return code. |
263 # Just in case catch this and and pass exit code to caller. | 263 # Just in case catch this and and pass exit code to caller. |
264 return inst.code | 264 return inst.code |
265 except socket.error as inst: | 265 except socket.error as inst: |
266 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst.args[-1])) | 266 ui.error(_("abort: %s\n") % stringutil.forcebytestr(inst.args[-1])) |
267 | 267 |
268 return -1 | 268 return -1 |
269 | 269 |
270 def checknewlabel(repo, lbl, kind): | 270 def checknewlabel(repo, lbl, kind): |
271 # Do not use the "kind" parameter in ui output. | 271 # Do not use the "kind" parameter in ui output. |