changeset 14605:9f1139cf5c76

hg: rearrange peer scheme lookup There is now only peer scheme lookup. Repository lookup goes through peer scheme lookup. When peer and repo types are finally separated, repo lookup will use peer.local() to get a repository object. The underbar is dropped so that extensions can patch the table.
author Matt Mackall <mpm@selenic.com>
date Mon, 13 Jun 2011 14:53:23 -0500
parents b1a534335548
children 6e631c24c6d9
files hgext/schemes.py mercurial/hg.py
diffstat 2 files changed, 22 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/schemes.py	Mon Jun 13 14:56:00 2011 +0300
+++ b/hgext/schemes.py	Mon Jun 13 14:53:23 2011 -0500
@@ -93,6 +93,6 @@
             and os.path.exists('%s:\\' % scheme)):
             raise util.Abort(_('custom scheme %s:// conflicts with drive '
                                'letter %s:\\\n') % (scheme, scheme.upper()))
-        hg._peerschemes[scheme] = ShortRepository(url, scheme, t)
+        hg.peerschemes[scheme] = ShortRepository(url, scheme, t)
 
     extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter)
--- a/mercurial/hg.py	Mon Jun 13 14:56:00 2011 +0300
+++ b/mercurial/hg.py	Mon Jun 13 14:53:23 2011 -0500
@@ -61,44 +61,7 @@
         u.fragment = None
     return str(u), (branch, branches or [])
 
-_reposchemes = {
-    'bundle': bundlerepo,
-    'file': _local,
-    'http': httprepo,
-    'https': httprepo,
-    'ssh': sshrepo,
-    'static-http': statichttprepo,
-}
-
-def _repolookup(path):
-    u = util.url(path)
-    scheme = u.scheme or 'file'
-    thing = _reposchemes.get(scheme) or _reposchemes['file']
-    try:
-        return thing(path)
-    except TypeError:
-        return thing
-
-def islocal(repo):
-    '''return true if repo or path is local'''
-    if isinstance(repo, str):
-        try:
-            return _repolookup(repo).islocal(repo)
-        except AttributeError:
-            return False
-    return repo.local()
-
-def repository(ui, path='', create=False):
-    """return a repository object for the specified path"""
-    repo = _repolookup(path).instance(ui, path, create)
-    ui = getattr(repo, "ui", ui)
-    for name, module in extensions.extensions():
-        hook = getattr(module, 'reposetup', None)
-        if hook:
-            hook(ui, repo)
-    return repo
-
-_peerschemes = {
+peerschemes = {
     'bundle': bundlerepo,
     'file': _local,
     'http': httprepo,
@@ -110,12 +73,31 @@
 def _peerlookup(path):
     u = util.url(path)
     scheme = u.scheme or 'file'
-    thing = _peerschemes.get(scheme) or _peerschemes['file']
+    thing = peerschemes.get(scheme) or peerschemes['file']
     try:
         return thing(path)
     except TypeError:
         return thing
 
+def islocal(repo):
+    '''return true if repo or path is local'''
+    if isinstance(repo, str):
+        try:
+            return _peerlookup(repo).islocal(repo)
+        except AttributeError:
+            return False
+    return repo.local()
+
+def repository(ui, path='', create=False):
+    """return a repository object for the specified path"""
+    repo = _peerlookup(path).instance(ui, path, create)
+    ui = getattr(repo, "ui", ui)
+    for name, module in extensions.extensions():
+        hook = getattr(module, 'reposetup', None)
+        if hook:
+            hook(ui, repo)
+    return repo
+
 def peer(ui, opts, path, create=False):
     '''return a repository peer for the specified path'''
     rui = remoteui(ui, opts)