Mercurial > hg
annotate contrib/showstack.py @ 37775:03d7f885d5f2
revsetlang: do not pass in non-bytes to parse()
Since parse() isn't a simple function, we shouldn't expect it would raise
TypeError or ValueError for invalid inputs. Before, TypeError was raised
at 'if pos != len(spec)', which was quite late to report an error.
This patch also makes tokenize() detect invalid object before converting
it to a py3-safe bytes.
Spotted while adding the 'revset(...)' hack to _parsewith().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 17 Apr 2018 21:59:58 +0900 |
parents | c9eb92fb87b7 |
children | acf5dbe39478 |
rev | line source |
---|---|
26123
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # showstack.py - extension to dump a Python stack trace on signal |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # binds to both SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) |
35656
c9eb92fb87b7
showstack: add an extension docstring
Boris Feld <boris.feld@octobus.net>
parents:
28522
diff
changeset
|
4 """dump stack trace when receiving SIGQUIT (Ctrl-\) and SIGINFO (Ctrl-T on BSDs) |
c9eb92fb87b7
showstack: add an extension docstring
Boris Feld <boris.feld@octobus.net>
parents:
28522
diff
changeset
|
5 """ |
26123
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 |
28522
f2fe7b199bb4
showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26123
diff
changeset
|
7 from __future__ import absolute_import |
f2fe7b199bb4
showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26123
diff
changeset
|
8 import signal |
f2fe7b199bb4
showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26123
diff
changeset
|
9 import sys |
f2fe7b199bb4
showstack: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26123
diff
changeset
|
10 import traceback |
26123
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
11 |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
12 def sigshow(*args): |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 sys.stderr.write("\n") |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
14 traceback.print_stack(args[1], limit=10, file=sys.stderr) |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
15 sys.stderr.write("----\n") |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
16 |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
17 def extsetup(ui): |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
18 signal.signal(signal.SIGQUIT, sigshow) |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
19 try: |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
20 signal.signal(signal.SIGINFO, sigshow) |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
21 except AttributeError: |
bdac264e5ed4
contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
22 pass |