Make hg paths and hg debugconfig work with -R/--repository option.
authorThomas Arendsen Hein <thomas@intevation.de>
Wed, 08 Mar 2006 01:30:43 +0100
changeset 1858 9fab6e903bae
parent 1857 848152a2e67f
child 1859 39c46510ed25
Make hg paths and hg debugconfig work with -R/--repository option. Commands that can use a repo, but don't need one, should be added to the "optionalrepo" string, similar to the "norepo" string.
mercurial/commands.py
--- a/mercurial/commands.py	Wed Mar 08 01:25:14 2006 +0100
+++ b/mercurial/commands.py	Wed Mar 08 01:30:43 2006 +0100
@@ -1058,13 +1058,8 @@
         error = _(".hg/dirstate inconsistent with current parent's manifest")
         raise util.Abort(error)
 
-def debugconfig(ui):
+def debugconfig(ui, repo):
     """show combined config settings from all hgrc files"""
-    try:
-        repo = hg.repository(ui)
-        ui = repo.ui
-    except hg.RepoError:
-        pass
     for section, name, value in ui.walkconfig():
         ui.write('%s.%s=%s\n' % (section, name, value))
 
@@ -1763,7 +1758,7 @@
         if n != nullid:
             show_changeset(ui, repo, changenode=n, brinfo=br)
 
-def paths(ui, search=None):
+def paths(ui, repo, search=None):
     """show definition of symbolic path names
 
     Show definition of symbolic path name NAME. If no name is given, show
@@ -1772,12 +1767,6 @@
     Path names are defined in the [paths] section of /etc/mercurial/hgrc
     and $HOME/.hgrc.  If run inside a repository, .hg/hgrc is used, too.
     """
-    try:
-        repo = hg.repository(ui)
-        ui = repo.ui
-    except hg.RepoError:
-        pass
-
     if search:
         for name, path in ui.configitems("paths"):
             if name == search:
@@ -2668,8 +2657,9 @@
     ('h', 'help', None, _('display help and exit')),
 ]
 
-norepo = ("clone init version help debugancestor debugconfig debugdata"
-          " debugindex debugindexdot paths")
+norepo = ("clone init version help debugancestor debugdata"
+          " debugindex debugindexdot")
+optionalrepo = ("paths debugconfig")
 
 def find(cmd):
     """Return (aliases, command table entry) for command string."""
@@ -2869,12 +2859,16 @@
                                      (options['cwd'], inst.strerror))
 
             if cmd not in norepo.split():
-                if not repo:
-                    repo = hg.repository(u, path=path)
-                u = repo.ui
-                for x in external:
-                    if hasattr(x, 'reposetup'):
-                        x.reposetup(u, repo)
+                try:
+                    if not repo:
+                        repo = hg.repository(u, path=path)
+                    u = repo.ui
+                    for x in external:
+                        if hasattr(x, 'reposetup'):
+                            x.reposetup(u, repo)
+                except hg.RepoError:
+                    if cmd not in optionalrepo.split():
+                        raise
                 d = lambda: func(u, repo, *args, **cmdoptions)
             else:
                 d = lambda: func(u, *args, **cmdoptions)