Show More
@@ -11,15 +11,19 import util, commands, hg, fancyopts, ex | |||||
11 | import cmdutil, encoding |
|
11 | import cmdutil, encoding | |
12 | import ui as uimod |
|
12 | import ui as uimod | |
13 |
|
13 | |||
|
14 | class request(object): | |||
|
15 | def __init__(self, args): | |||
|
16 | self.args = args | |||
|
17 | ||||
14 | def run(): |
|
18 | def run(): | |
15 | "run the command in sys.argv" |
|
19 | "run the command in sys.argv" | |
16 | sys.exit(dispatch(sys.argv[1:])) |
|
20 | sys.exit(dispatch(request(sys.argv[1:]))) | |
17 |
|
21 | |||
18 |
def dispatch( |
|
22 | def dispatch(req): | |
19 | "run the command specified in args" |
|
23 | "run the command specified in req.args" | |
20 | try: |
|
24 | try: | |
21 | u = uimod.ui() |
|
25 | u = uimod.ui() | |
22 | if '--traceback' in args: |
|
26 | if '--traceback' in req.args: | |
23 | u.setconfig('ui', 'traceback', 'on') |
|
27 | u.setconfig('ui', 'traceback', 'on') | |
24 | except util.Abort, inst: |
|
28 | except util.Abort, inst: | |
25 | sys.stderr.write(_("abort: %s\n") % inst) |
|
29 | sys.stderr.write(_("abort: %s\n") % inst) | |
@@ -33,9 +37,9 def dispatch(args): | |||||
33 | else: |
|
37 | else: | |
34 | sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0]) |
|
38 | sys.stderr.write(_("hg: parse error: %s\n") % inst.args[0]) | |
35 | return -1 |
|
39 | return -1 | |
36 |
return _runcatch(u, |
|
40 | return _runcatch(u, req) | |
37 |
|
41 | |||
38 |
def _runcatch(ui, |
|
42 | def _runcatch(ui, req): | |
39 | def catchterm(*args): |
|
43 | def catchterm(*args): | |
40 | raise error.SignalInterrupt |
|
44 | raise error.SignalInterrupt | |
41 |
|
45 | |||
@@ -50,17 +54,17 def _runcatch(ui, args): | |||||
50 | try: |
|
54 | try: | |
51 | try: |
|
55 | try: | |
52 | # enter the debugger before command execution |
|
56 | # enter the debugger before command execution | |
53 | if '--debugger' in args: |
|
57 | if '--debugger' in req.args: | |
54 | ui.warn(_("entering debugger - " |
|
58 | ui.warn(_("entering debugger - " | |
55 | "type c to continue starting hg or h for help\n")) |
|
59 | "type c to continue starting hg or h for help\n")) | |
56 | pdb.set_trace() |
|
60 | pdb.set_trace() | |
57 | try: |
|
61 | try: | |
58 |
return _dispatch(ui, |
|
62 | return _dispatch(ui, req) | |
59 | finally: |
|
63 | finally: | |
60 | ui.flush() |
|
64 | ui.flush() | |
61 | except: |
|
65 | except: | |
62 | # enter the debugger when we hit an exception |
|
66 | # enter the debugger when we hit an exception | |
63 | if '--debugger' in args: |
|
67 | if '--debugger' in req.args: | |
64 | traceback.print_exc() |
|
68 | traceback.print_exc() | |
65 | pdb.post_mortem(sys.exc_info()[2]) |
|
69 | pdb.post_mortem(sys.exc_info()[2]) | |
66 | ui.traceback() |
|
70 | ui.traceback() | |
@@ -486,7 +490,8 def _checkshellalias(ui, args): | |||||
486 | os.chdir(cwd) |
|
490 | os.chdir(cwd) | |
487 |
|
491 | |||
488 | _loaded = set() |
|
492 | _loaded = set() | |
489 |
def _dispatch(ui, |
|
493 | def _dispatch(ui, req): | |
|
494 | args = req.args | |||
490 | shellaliasfn = _checkshellalias(ui, args) |
|
495 | shellaliasfn = _checkshellalias(ui, args) | |
491 | if shellaliasfn: |
|
496 | if shellaliasfn: | |
492 | return shellaliasfn() |
|
497 | return shellaliasfn() | |
@@ -596,7 +601,8 def _dispatch(ui, args): | |||||
596 | repos = map(cmdutil.findrepo, args) |
|
601 | repos = map(cmdutil.findrepo, args) | |
597 | guess = repos[0] |
|
602 | guess = repos[0] | |
598 | if guess and repos.count(guess) == len(repos): |
|
603 | if guess and repos.count(guess) == len(repos): | |
599 |
re |
|
604 | req.args = ['--repository', guess] + fullargs | |
|
605 | return _dispatch(ui, req) | |||
600 | if not path: |
|
606 | if not path: | |
601 | raise error.RepoError(_("no repository found in %r" |
|
607 | raise error.RepoError(_("no repository found in %r" | |
602 | " (.hg not found)") % os.getcwd()) |
|
608 | " (.hg not found)") % os.getcwd()) |
@@ -7,7 +7,8 def testdispatch(cmd): | |||||
7 | Prints command and result value, but does not handle quoting. |
|
7 | Prints command and result value, but does not handle quoting. | |
8 | """ |
|
8 | """ | |
9 | print "running: %s" % (cmd,) |
|
9 | print "running: %s" % (cmd,) | |
10 |
re |
|
10 | req = dispatch.request(cmd.split()) | |
|
11 | result = dispatch.dispatch(req) | |||
11 | print "result: %r" % (result,) |
|
12 | print "result: %r" % (result,) | |
12 |
|
13 | |||
13 |
|
14 |
General Comments 0
You need to be logged in to leave comments.
Login now