annotate contrib/showstack.py @ 41720:6704696141b8

templates: adding a config() function for template customization This allows templates to be written such that users can customize them easily, or that they can be customized based on other configuration of the system. For enterprise deployments, we often have complex template aliases, and right now the only way individual users can customize those is by replacing the whole template alias (which means they won't get company-wide updates to it anymore, plus most users don't want to have to get a complex template right). With this change, they can just set a config option which feeds into our templates for common changes (e.g. whether to limit commit descriptions to the width of their terminal or not). To work around the issue of having to register the config options, I declared a dedicated section [templateconfig] for these options to be dynamically declared. They can still reference any other config option that's registered elsewhere. I only did string, bool and int at this time - list and date would add other complications with parsing the default so I'll leave that as an exercise to the reader :) Differential Revision: https://phab.mercurial-scm.org/D5959
author rdamazio@google.com
date Wed, 13 Feb 2019 18:34:08 -0800
parents 6dae1f31c6c9
children 2372284d9457
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
41548
6dae1f31c6c9 showstack: use raw docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40036
diff changeset
4 r"""dump stack trace when receiving SIGQUIT (Ctrl-\) or SIGINFO (Ctrl-T on BSDs)
35656
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
40036
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
7 from __future__ import absolute_import, print_function
28522
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
40036
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
17 def sigexit(*args):
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
18 sigshow(*args)
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
19 print('alarm!')
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
20 sys.exit(1)
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
21
26123
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
22 def extsetup(ui):
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
23 signal.signal(signal.SIGQUIT, sigshow)
40036
acf5dbe39478 showstack: also handle SIGALRM
Augie Fackler <augie@google.com>
parents: 35656
diff changeset
24 signal.signal(signal.SIGALRM, sigexit)
26123
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
25 try:
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
26 signal.signal(signal.SIGINFO, sigshow)
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
27 except AttributeError:
bdac264e5ed4 contrib: add showstack extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
28 pass