[PATCH 1 of 2] dispatch: wrap dispatch related information in a request class

Idan Kamara idankk86 at gmail.com
Wed May 25 16:53:39 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1306359851 -10800
# Node ID 3db8a833fcc25e43d3d5657041df0346d7aeef31
# Parent  a6b543e053058c39b52e2b7c1e9a4b7c14c66a56
dispatch: wrap dispatch related information in a request class

currently only stores the arguments.

diff -r a6b543e05305 -r 3db8a833fcc2 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Wed May 25 10:06:17 2011 +0200
+++ b/mercurial/dispatch.py	Thu May 26 00:44:11 2011 +0300
@@ -11,15 +11,19 @@
 import cmdutil, encoding
 import ui as uimod
 
+class request(object):
+    def __init__(self, args):
+        self.args = args
+
 def run():
     "run the command in sys.argv"
-    sys.exit(dispatch(sys.argv[1:]))
+    sys.exit(dispatch(request(sys.argv[1:])))
 
-def dispatch(args):
-    "run the command specified in args"
+def dispatch(req):
+    "run the command specified in req.args"
     try:
         u = uimod.ui()
-        if '--traceback' in args:
+        if '--traceback' in req.args:
             u.setconfig('ui', 'traceback', 'on')
     except util.Abort, inst:
         sys.stderr.write(_("abort: %s\n") % inst)
@@ -33,9 +37,9 @@
         else:
             sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0])
         return -1
-    return _runcatch(u, args)
+    return _runcatch(u, req)
 
-def _runcatch(ui, args):
+def _runcatch(ui, req):
     def catchterm(*args):
         raise error.SignalInterrupt
 
@@ -50,17 +54,17 @@
     try:
         try:
             # enter the debugger before command execution
-            if '--debugger' in args:
+            if '--debugger' in req.args:
                 ui.warn(_("entering debugger - "
                         "type c to continue starting hg or h for help\n"))
                 pdb.set_trace()
             try:
-                return _dispatch(ui, args)
+                return _dispatch(ui, req)
             finally:
                 ui.flush()
         except:
             # enter the debugger when we hit an exception
-            if '--debugger' in args:
+            if '--debugger' in req.args:
                 traceback.print_exc()
                 pdb.post_mortem(sys.exc_info()[2])
             ui.traceback()
@@ -486,7 +490,8 @@
     os.chdir(cwd)
 
 _loaded = set()
-def _dispatch(ui, args):
+def _dispatch(ui, req):
+    args = req.args
     shellaliasfn = _checkshellalias(ui, args)
     if shellaliasfn:
         return shellaliasfn()
@@ -596,7 +601,8 @@
                     repos = map(cmdutil.findrepo, args)
                     guess = repos[0]
                     if guess and repos.count(guess) == len(repos):
-                        return _dispatch(ui, ['--repository', guess] + fullargs)
+                        req.args = ['--repository', guess] + fullargs
+                        return _dispatch(ui, req)
                 if not path:
                     raise error.RepoError(_("no repository found in %r"
                                             " (.hg not found)") % os.getcwd())
diff -r a6b543e05305 -r 3db8a833fcc2 tests/test-dispatch.py
--- a/tests/test-dispatch.py	Wed May 25 10:06:17 2011 +0200
+++ b/tests/test-dispatch.py	Thu May 26 00:44:11 2011 +0300
@@ -7,7 +7,8 @@
     Prints command and result value, but does not handle quoting.
     """
     print "running: %s" % (cmd,)
-    result = dispatch.dispatch(cmd.split())
+    req = dispatch.request(cmd.split())
+    result = dispatch.dispatch(req)
     print "result: %r" % (result,)
 
 


More information about the Mercurial-devel mailing list