Patchwork [02,of,35] debugshell: declare command using decorator

login
register
mail settings
Submitter Gregory Szorc
Date May 5, 2014, 5:51 a.m.
Message ID <24436ea8cf91fa45945a.1399269067@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4593/
State Accepted
Commit 8b5c039f2b4f888e3006eec0172fd4ec2f18c3b5
Headers show

Comments

Gregory Szorc - May 5, 2014, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1399263571 25200
#      Sun May 04 21:19:31 2014 -0700
# Branch stable
# Node ID 24436ea8cf91fa45945a4d9b82d6841f1537afd3
# Parent  a40ee6509498e00f2c4003cc5b1712738ee784fa
debugshell: declare command using decorator

Patch

diff --git a/contrib/debugshell.py b/contrib/debugshell.py
--- a/contrib/debugshell.py
+++ b/contrib/debugshell.py
@@ -1,14 +1,18 @@ 
 # debugshell extension
 """a python shell with repo, changelog & manifest objects"""
 
 import sys
 import mercurial
 import code
+from mercurial import cmdutil
+
+cmdtable = {}
+command = cmdutil.command(cmdtable)
 
 def pdb(ui, repo, msg, **opts):
     objects = {
         'mercurial': mercurial,
         'repo': repo,
         'cl': repo.changelog,
         'mf': repo.manifest,
     }
@@ -19,16 +23,17 @@  def ipdb(ui, repo, msg, **opts):
     import IPython
 
     cl = repo.changelog
     mf = repo.manifest
     cl, mf # use variables to appease pyflakes
 
     IPython.embed()
 
+@command('debugshell|dbsh', [])
 def debugshell(ui, repo, **opts):
     bannermsg = "loaded repo : %s\n" \
                 "using source: %s" % (repo.root,
                                       mercurial.__path__[0])
 
     pdbmap = {
         'pdb'  : 'code',
         'ipdb' : 'IPython'
@@ -42,12 +47,8 @@  def debugshell(ui, repo, **opts):
     try:
         __import__(pdbmap[debugger])
     except ImportError:
         ui.warn("%s debugger specified but %s module was not found\n"
                 % (debugger, pdbmap[debugger]))
         debugger = 'pdb'
 
     getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts)
-
-cmdtable = {
-    "debugshell|dbsh": (debugshell, [])
-}