[PATCH] dispatch: add repo to the request

Idan Kamara idankk86 at gmail.com
Wed Jun 1 16:54:56 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1306964614 -10800
# Node ID eccbb9980ada13088722a3ab88117cb8c8c8c37e
# Parent  4f695345979c395f6492fcf3343235e571032300
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.

diff -r 4f695345979c -r eccbb9980ada mercurial/dispatch.py
--- a/mercurial/dispatch.py	Wed Jun 01 16:42:50 2011 -0500
+++ b/mercurial/dispatch.py	Thu Jun 02 00:43:34 2011 +0300
@@ -12,9 +12,10 @@
 import ui as uimod
 
 class request(object):
-    def __init__(self, args, ui=None):
+    def __init__(self, args, ui=None, repo=None):
         self.args = args
         self.ui = ui
+        self.repo = repo
 
 def run():
     "run the command in sys.argv"
@@ -592,26 +593,31 @@
     repo = None
     cmdpats = args[:]
     if cmd not in commands.norepo.split():
-        try:
-            repo = hg.repository(ui, path=path)
-            ui = repo.ui
-            if not repo.local():
-                raise util.Abort(_("repository '%s' is not local") % path)
-            ui.setconfig("bundle", "mainreporoot", repo.root)
-        except error.RequirementError:
-            raise
-        except error.RepoError:
-            if cmd not in commands.optionalrepo.split():
-                if args and not path: # try to infer -R from command args
-                    repos = map(cmdutil.findrepo, args)
-                    guess = repos[0]
-                    if guess and repos.count(guess) == len(repos):
-                        req.args = ['--repository', guess] + fullargs
-                        return _dispatch(req)
-                if not path:
-                    raise error.RepoError(_("no repository found in %r"
-                                            " (.hg not found)") % os.getcwd())
+        # use the repo from the request only if we don't have -R
+        if not rpath:
+            repo = req.repo
+
+        if not repo:
+            try:
+                repo = hg.repository(ui, path=path)
+                ui = repo.ui
+                if not repo.local():
+                    raise util.Abort(_("repository '%s' is not local") % path)
+                ui.setconfig("bundle", "mainreporoot", repo.root)
+            except error.RequirementError:
                 raise
+            except error.RepoError:
+                if cmd not in commands.optionalrepo.split():
+                    if args and not path: # try to infer -R from command args
+                        repos = map(cmdutil.findrepo, args)
+                        guess = repos[0]
+                        if guess and repos.count(guess) == len(repos):
+                            req.args = ['--repository', guess] + fullargs
+                            return _dispatch(req)
+                    if not path:
+                        raise error.RepoError(_("no repository found in %r"
+                                                " (.hg not found)") % os.getcwd())
+                    raise
         args.insert(0, repo)
     elif rpath:
         ui.warn(_("warning: --repository ignored\n"))


More information about the Mercurial-devel mailing list