comparison mercurial/dispatch.py @ 14510:eccbb9980ada

dispatch: add repo to the request allows callers of dispatch.dispatch to pass in an initialized repo object to be used. -R/--repository overrides the request repo.
author Idan Kamara <idankk86@gmail.com>
date Thu, 02 Jun 2011 00:43:34 +0300
parents 80c599eee3f3
children 25c1f3ddd927
comparison
equal deleted inserted replaced
14509:4f695345979c 14510:eccbb9980ada
10 import util, commands, hg, fancyopts, extensions, hook, error 10 import util, commands, hg, fancyopts, extensions, hook, error
11 import cmdutil, encoding 11 import cmdutil, encoding
12 import ui as uimod 12 import ui as uimod
13 13
14 class request(object): 14 class request(object):
15 def __init__(self, args, ui=None): 15 def __init__(self, args, ui=None, repo=None):
16 self.args = args 16 self.args = args
17 self.ui = ui 17 self.ui = ui
18 self.repo = repo
18 19
19 def run(): 20 def run():
20 "run the command in sys.argv" 21 "run the command in sys.argv"
21 sys.exit(dispatch(request(sys.argv[1:]))) 22 sys.exit(dispatch(request(sys.argv[1:])))
22 23
590 return commands.help_(ui, 'shortlist') 591 return commands.help_(ui, 'shortlist')
591 592
592 repo = None 593 repo = None
593 cmdpats = args[:] 594 cmdpats = args[:]
594 if cmd not in commands.norepo.split(): 595 if cmd not in commands.norepo.split():
595 try: 596 # use the repo from the request only if we don't have -R
596 repo = hg.repository(ui, path=path) 597 if not rpath:
597 ui = repo.ui 598 repo = req.repo
598 if not repo.local(): 599
599 raise util.Abort(_("repository '%s' is not local") % path) 600 if not repo:
600 ui.setconfig("bundle", "mainreporoot", repo.root) 601 try:
601 except error.RequirementError: 602 repo = hg.repository(ui, path=path)
602 raise 603 ui = repo.ui
603 except error.RepoError: 604 if not repo.local():
604 if cmd not in commands.optionalrepo.split(): 605 raise util.Abort(_("repository '%s' is not local") % path)
605 if args and not path: # try to infer -R from command args 606 ui.setconfig("bundle", "mainreporoot", repo.root)
606 repos = map(cmdutil.findrepo, args) 607 except error.RequirementError:
607 guess = repos[0]
608 if guess and repos.count(guess) == len(repos):
609 req.args = ['--repository', guess] + fullargs
610 return _dispatch(req)
611 if not path:
612 raise error.RepoError(_("no repository found in %r"
613 " (.hg not found)") % os.getcwd())
614 raise 608 raise
609 except error.RepoError:
610 if cmd not in commands.optionalrepo.split():
611 if args and not path: # try to infer -R from command args
612 repos = map(cmdutil.findrepo, args)
613 guess = repos[0]
614 if guess and repos.count(guess) == len(repos):
615 req.args = ['--repository', guess] + fullargs
616 return _dispatch(req)
617 if not path:
618 raise error.RepoError(_("no repository found in %r"
619 " (.hg not found)") % os.getcwd())
620 raise
615 args.insert(0, repo) 621 args.insert(0, repo)
616 elif rpath: 622 elif rpath:
617 ui.warn(_("warning: --repository ignored\n")) 623 ui.warn(_("warning: --repository ignored\n"))
618 624
619 msg = ' '.join(' ' in a and repr(a) or a for a in fullargs) 625 msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)