comparison mercurial/commands.py @ 1225:ea90162e210c

Add --debugger global option With this option, hg will drop into the Python debugger on execution. Running 'continue' will execute normally, and the debugger will be reinvoked if an exception is raised.
author mpm@selenic.com
date Thu, 08 Sep 2005 17:09:31 -0700
parents a5cb17a2d240
children e3ea354d99b2
comparison
equal deleted inserted replaced
1224:cc61d366bc3b 1225:ea90162e210c
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from demandload import demandload 8 from demandload import demandload
9 from node import * 9 from node import *
10 demandload(globals(), "os re sys signal shutil imp urllib") 10 demandload(globals(), "os re sys signal shutil imp urllib pdb")
11 demandload(globals(), "fancyopts ui hg util lock revlog") 11 demandload(globals(), "fancyopts ui hg util lock revlog")
12 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") 12 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
13 demandload(globals(), "errno socket version struct atexit sets bz2") 13 demandload(globals(), "errno socket version struct atexit sets bz2")
14 14
15 class UnknownCommand(Exception): 15 class UnknownCommand(Exception):
1847 ('', 'cwd', '', 'change working directory'), 1847 ('', 'cwd', '', 'change working directory'),
1848 ('y', 'noninteractive', None, 'run non-interactively'), 1848 ('y', 'noninteractive', None, 'run non-interactively'),
1849 ('q', 'quiet', None, 'quiet mode'), 1849 ('q', 'quiet', None, 'quiet mode'),
1850 ('v', 'verbose', None, 'verbose mode'), 1850 ('v', 'verbose', None, 'verbose mode'),
1851 ('', 'debug', None, 'debug mode'), 1851 ('', 'debug', None, 'debug mode'),
1852 ('', 'debugger', None, 'start debugger'),
1852 ('', 'traceback', None, 'print traceback on exception'), 1853 ('', 'traceback', None, 'print traceback on exception'),
1853 ('', 'time', None, 'time how long the command takes'), 1854 ('', 'time', None, 'time how long the command takes'),
1854 ('', 'profile', None, 'profile'), 1855 ('', 'profile', None, 'profile'),
1855 ('', 'version', None, 'output version information and exit'), 1856 ('', 'version', None, 'output version information and exit'),
1856 ('h', 'help', None, 'display help and exit'), 1857 ('h', 'help', None, 'display help and exit'),
1968 atexit.register(print_time) 1969 atexit.register(print_time)
1969 1970
1970 u.updateopts(options["verbose"], options["debug"], options["quiet"], 1971 u.updateopts(options["verbose"], options["debug"], options["quiet"],
1971 not options["noninteractive"]) 1972 not options["noninteractive"])
1972 1973
1974 # enter the debugger before command execution
1975 if options['debugger']:
1976 pdb.set_trace()
1977
1973 try: 1978 try:
1974 try: 1979 try:
1975 if options['help']: 1980 if options['help']:
1976 help_(u, cmd, options['version']) 1981 help_(u, cmd, options['version'])
1977 sys.exit(0) 1982 sys.exit(0)
2009 stats.print_stats(40) 2014 stats.print_stats(40)
2010 return r 2015 return r
2011 else: 2016 else:
2012 return d() 2017 return d()
2013 except: 2018 except:
2019 # enter the debugger when we hit an exception
2020 if options['debugger']:
2021 pdb.post_mortem(sys.exc_info()[2])
2014 if options['traceback']: 2022 if options['traceback']:
2015 traceback.print_exc() 2023 traceback.print_exc()
2016 raise 2024 raise
2017 except hg.RepoError, inst: 2025 except hg.RepoError, inst:
2018 u.warn("abort: ", inst, "!\n") 2026 u.warn("abort: ", inst, "!\n")