changeset 14439:80c599eee3f3

dispatch: use the request to store the ui object and check if we got one before creating. note that the contents of the ui object might change after dispatch() returns (by options passed through --config for example), to ensure it doesn't, pass a copy() of it.
author Idan Kamara <idankk86@gmail.com>
date Thu, 26 May 2011 00:53:23 +0300
parents 08bfec2ef031
children 96f1c1b14154
files mercurial/dispatch.py
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Thu May 26 00:44:11 2011 +0300
+++ b/mercurial/dispatch.py	Thu May 26 00:53:23 2011 +0300
@@ -12,8 +12,9 @@
 import ui as uimod
 
 class request(object):
-    def __init__(self, args):
+    def __init__(self, args, ui=None):
         self.args = args
+        self.ui = ui
 
 def run():
     "run the command in sys.argv"
@@ -22,9 +23,10 @@
 def dispatch(req):
     "run the command specified in req.args"
     try:
-        u = uimod.ui()
+        if not req.ui:
+            req.ui = uimod.ui()
         if '--traceback' in req.args:
-            u.setconfig('ui', 'traceback', 'on')
+            req.ui.setconfig('ui', 'traceback', 'on')
     except util.Abort, inst:
         sys.stderr.write(_("abort: %s\n") % inst)
         if inst.hint:
@@ -37,12 +39,13 @@
         else:
             sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0])
         return -1
-    return _runcatch(u, req)
+    return _runcatch(req)
 
-def _runcatch(ui, req):
+def _runcatch(req):
     def catchterm(*args):
         raise error.SignalInterrupt
 
+    ui = req.ui
     try:
         for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
             num = getattr(signal, name, None)
@@ -59,7 +62,7 @@
                         "type c to continue starting hg or h for help\n"))
                 pdb.set_trace()
             try:
-                return _dispatch(ui, req)
+                return _dispatch(req)
             finally:
                 ui.flush()
         except:
@@ -490,8 +493,10 @@
     os.chdir(cwd)
 
 _loaded = set()
-def _dispatch(ui, req):
+def _dispatch(req):
     args = req.args
+    ui = req.ui
+
     shellaliasfn = _checkshellalias(ui, args)
     if shellaliasfn:
         return shellaliasfn()
@@ -602,7 +607,7 @@
                     guess = repos[0]
                     if guess and repos.count(guess) == len(repos):
                         req.args = ['--repository', guess] + fullargs
-                        return _dispatch(ui, req)
+                        return _dispatch(req)
                 if not path:
                     raise error.RepoError(_("no repository found in %r"
                                             " (.hg not found)") % os.getcwd())