# HG changeset patch # User Idan Kamara # Date 1306359851 -10800 # Node ID 08bfec2ef031e85807af45636352f1f96ed2557c # Parent cbe13e6bdc34ac60bc8475ae2022f0bed0169a70 dispatch: wrap dispatch related information in a request class currently only stores the arguments. diff -r cbe13e6bdc34 -r 08bfec2ef031 mercurial/dispatch.py --- a/mercurial/dispatch.py Thu May 26 22:51:02 2011 +0800 +++ 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 cbe13e6bdc34 -r 08bfec2ef031 tests/test-dispatch.py --- a/tests/test-dispatch.py Thu May 26 22:51:02 2011 +0800 +++ 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,)