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.
--- 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)