# HG changeset patch # User Matt Mackall # Date 2011-06-11 19:14:52 # Node ID 5f002e3336ba006b577df705b9618d9b833a8800 # Parent b72cef1b8b26262f627423c16b5c09396721b220 hg: split peer and repo lookup tables diff --git a/hgext/schemes.py b/hgext/schemes.py --- a/hgext/schemes.py +++ b/hgext/schemes.py @@ -69,7 +69,7 @@ class ShortRepository(object): tail = '' context = dict((str(i + 1), v) for i, v in enumerate(parts)) url = ''.join(self.templater.process(self.url, context)) + tail - return hg._lookup(url).instance(ui, url, create) + return hg._peerlookup(url).instance(ui, url, create) def hasdriveletter(orig, path): for scheme in schemes: @@ -93,6 +93,6 @@ def extsetup(ui): and os.path.exists('%s:\\' % scheme)): raise util.Abort(_('custom scheme %s:// conflicts with drive ' 'letter %s:\\\n') % (scheme, scheme.upper())) - hg.schemes[scheme] = ShortRepository(url, scheme, t) + hg._peerschemes[scheme] = ShortRepository(url, scheme, t) extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter) diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -61,7 +61,7 @@ def parseurl(path, branches=None): u.fragment = None return str(u), (branch, branches or []) -schemes = { +_reposchemes = { 'bundle': bundlerepo, 'file': _local, 'http': httprepo, @@ -70,10 +70,10 @@ schemes = { 'static-http': statichttprepo, } -def _lookup(path): +def _repolookup(path): u = util.url(path) scheme = u.scheme or 'file' - thing = schemes.get(scheme) or schemes['file'] + thing = _reposchemes.get(scheme) or _reposchemes['file'] try: return thing(path) except TypeError: @@ -83,14 +83,14 @@ def islocal(repo): '''return true if repo or path is local''' if isinstance(repo, str): try: - return _lookup(repo).islocal(repo) + 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 = _lookup(path).instance(ui, path, create) + repo = _repolookup(path).instance(ui, path, create) ui = getattr(repo, "ui", ui) for name, module in extensions.extensions(): hook = getattr(module, 'reposetup', None) @@ -98,10 +98,28 @@ def repository(ui, path='', create=False hook(ui, repo) return repo +_peerschemes = { + 'bundle': bundlerepo, + 'file': _local, + 'http': httprepo, + 'https': httprepo, + 'ssh': sshrepo, + 'static-http': statichttprepo, +} + +def _peerlookup(path): + u = util.url(path) + scheme = u.scheme or 'file' + thing = _peerschemes.get(scheme) or _peerschemes['file'] + try: + return thing(path) + except TypeError: + return thing + def peer(ui, opts, path, create=False): '''return a repository peer for the specified path''' rui = remoteui(ui, opts) - return _lookup(path).instance(rui, path, create) + return _peerlookup(path).instance(rui, path, create) def defaultdest(source): '''return default destination of clone if none is given'''