diff 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
line wrap: on
line diff
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -7,7 +7,7 @@
 
 from demandload import demandload
 from node import *
-demandload(globals(), "os re sys signal shutil imp urllib")
+demandload(globals(), "os re sys signal shutil imp urllib pdb")
 demandload(globals(), "fancyopts ui hg util lock revlog")
 demandload(globals(), "fnmatch hgweb mdiff random signal time traceback")
 demandload(globals(), "errno socket version struct atexit sets bz2")
@@ -1849,6 +1849,7 @@ globalopts = [
     ('q', 'quiet', None, 'quiet mode'),
     ('v', 'verbose', None, 'verbose mode'),
     ('', 'debug', None, 'debug mode'),
+    ('', 'debugger', None, 'start debugger'),
     ('', 'traceback', None, 'print traceback on exception'),
     ('', 'time', None, 'time how long the command takes'),
     ('', 'profile', None, 'profile'),
@@ -1970,6 +1971,10 @@ def dispatch(args):
     u.updateopts(options["verbose"], options["debug"], options["quiet"],
               not options["noninteractive"])
 
+    # enter the debugger before command execution
+    if options['debugger']:
+        pdb.set_trace()
+
     try:
         try:
             if options['help']:
@@ -2011,6 +2016,9 @@ def dispatch(args):
             else:
                 return d()
         except:
+            # enter the debugger when we hit an exception
+            if options['debugger']:
+                pdb.post_mortem(sys.exc_info()[2])
             if options['traceback']:
                 traceback.print_exc()
             raise