##// END OF EJS Templates
hg: split peer and repo lookup tables
Matt Mackall -
r14568:5f002e33 default
parent child Browse files
Show More
@@ -69,7 +69,7 class ShortRepository(object):
69 tail = ''
69 tail = ''
70 context = dict((str(i + 1), v) for i, v in enumerate(parts))
70 context = dict((str(i + 1), v) for i, v in enumerate(parts))
71 url = ''.join(self.templater.process(self.url, context)) + tail
71 url = ''.join(self.templater.process(self.url, context)) + tail
72 return hg._lookup(url).instance(ui, url, create)
72 return hg._peerlookup(url).instance(ui, url, create)
73
73
74 def hasdriveletter(orig, path):
74 def hasdriveletter(orig, path):
75 for scheme in schemes:
75 for scheme in schemes:
@@ -93,6 +93,6 def extsetup(ui):
93 and os.path.exists('%s:\\' % scheme)):
93 and os.path.exists('%s:\\' % scheme)):
94 raise util.Abort(_('custom scheme %s:// conflicts with drive '
94 raise util.Abort(_('custom scheme %s:// conflicts with drive '
95 'letter %s:\\\n') % (scheme, scheme.upper()))
95 'letter %s:\\\n') % (scheme, scheme.upper()))
96 hg.schemes[scheme] = ShortRepository(url, scheme, t)
96 hg._peerschemes[scheme] = ShortRepository(url, scheme, t)
97
97
98 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter)
98 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter)
@@ -61,7 +61,7 def parseurl(path, branches=None):
61 u.fragment = None
61 u.fragment = None
62 return str(u), (branch, branches or [])
62 return str(u), (branch, branches or [])
63
63
64 schemes = {
64 _reposchemes = {
65 'bundle': bundlerepo,
65 'bundle': bundlerepo,
66 'file': _local,
66 'file': _local,
67 'http': httprepo,
67 'http': httprepo,
@@ -70,10 +70,10 schemes = {
70 'static-http': statichttprepo,
70 'static-http': statichttprepo,
71 }
71 }
72
72
73 def _lookup(path):
73 def _repolookup(path):
74 u = util.url(path)
74 u = util.url(path)
75 scheme = u.scheme or 'file'
75 scheme = u.scheme or 'file'
76 thing = schemes.get(scheme) or schemes['file']
76 thing = _reposchemes.get(scheme) or _reposchemes['file']
77 try:
77 try:
78 return thing(path)
78 return thing(path)
79 except TypeError:
79 except TypeError:
@@ -83,14 +83,14 def islocal(repo):
83 '''return true if repo or path is local'''
83 '''return true if repo or path is local'''
84 if isinstance(repo, str):
84 if isinstance(repo, str):
85 try:
85 try:
86 return _lookup(repo).islocal(repo)
86 return _repolookup(repo).islocal(repo)
87 except AttributeError:
87 except AttributeError:
88 return False
88 return False
89 return repo.local()
89 return repo.local()
90
90
91 def repository(ui, path='', create=False):
91 def repository(ui, path='', create=False):
92 """return a repository object for the specified path"""
92 """return a repository object for the specified path"""
93 repo = _lookup(path).instance(ui, path, create)
93 repo = _repolookup(path).instance(ui, path, create)
94 ui = getattr(repo, "ui", ui)
94 ui = getattr(repo, "ui", ui)
95 for name, module in extensions.extensions():
95 for name, module in extensions.extensions():
96 hook = getattr(module, 'reposetup', None)
96 hook = getattr(module, 'reposetup', None)
@@ -98,10 +98,28 def repository(ui, path='', create=False
98 hook(ui, repo)
98 hook(ui, repo)
99 return repo
99 return repo
100
100
101 _peerschemes = {
102 'bundle': bundlerepo,
103 'file': _local,
104 'http': httprepo,
105 'https': httprepo,
106 'ssh': sshrepo,
107 'static-http': statichttprepo,
108 }
109
110 def _peerlookup(path):
111 u = util.url(path)
112 scheme = u.scheme or 'file'
113 thing = _peerschemes.get(scheme) or _peerschemes['file']
114 try:
115 return thing(path)
116 except TypeError:
117 return thing
118
101 def peer(ui, opts, path, create=False):
119 def peer(ui, opts, path, create=False):
102 '''return a repository peer for the specified path'''
120 '''return a repository peer for the specified path'''
103 rui = remoteui(ui, opts)
121 rui = remoteui(ui, opts)
104 return _lookup(path).instance(rui, path, create)
122 return _peerlookup(path).instance(rui, path, create)
105
123
106 def defaultdest(source):
124 def defaultdest(source):
107 '''return default destination of clone if none is given'''
125 '''return default destination of clone if none is given'''
General Comments 0
You need to be logged in to leave comments. Login now