Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 32379:71e735bd8170
dispatch: make request accept additional reposetups
chg needs special logic around repo object creation (like, collecting and
reporting repo path to the master server). Adding "reposetup" to
dispatch.request seems to be an easy and reasonably clean way to allow that.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sat, 29 Apr 2017 21:39:47 -0700 |
parents | 448ed4d3ee90 |
children | 963de566de2f |
comparison
equal
deleted
inserted
replaced
32378:7d0c69505a66 | 32379:71e735bd8170 |
---|---|
146 return url.open(ui, path) | 146 return url.open(ui, path) |
147 | 147 |
148 # a list of (ui, repo) functions called for wire peer initialization | 148 # a list of (ui, repo) functions called for wire peer initialization |
149 wirepeersetupfuncs = [] | 149 wirepeersetupfuncs = [] |
150 | 150 |
151 def _peerorrepo(ui, path, create=False): | 151 def _peerorrepo(ui, path, create=False, presetupfuncs=None): |
152 """return a repository object for the specified path""" | 152 """return a repository object for the specified path""" |
153 obj = _peerlookup(path).instance(ui, path, create) | 153 obj = _peerlookup(path).instance(ui, path, create) |
154 ui = getattr(obj, "ui", ui) | 154 ui = getattr(obj, "ui", ui) |
155 for f in presetupfuncs or []: | |
156 f(ui, obj) | |
155 for name, module in extensions.extensions(ui): | 157 for name, module in extensions.extensions(ui): |
156 hook = getattr(module, 'reposetup', None) | 158 hook = getattr(module, 'reposetup', None) |
157 if hook: | 159 if hook: |
158 hook(ui, obj) | 160 hook(ui, obj) |
159 if not obj.local(): | 161 if not obj.local(): |
160 for f in wirepeersetupfuncs: | 162 for f in wirepeersetupfuncs: |
161 f(ui, obj) | 163 f(ui, obj) |
162 return obj | 164 return obj |
163 | 165 |
164 def repository(ui, path='', create=False): | 166 def repository(ui, path='', create=False, presetupfuncs=None): |
165 """return a repository object for the specified path""" | 167 """return a repository object for the specified path""" |
166 peer = _peerorrepo(ui, path, create) | 168 peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs) |
167 repo = peer.local() | 169 repo = peer.local() |
168 if not repo: | 170 if not repo: |
169 raise error.Abort(_("repository '%s' is not local") % | 171 raise error.Abort(_("repository '%s' is not local") % |
170 (path or peer.url())) | 172 (path or peer.url())) |
171 return repo.filtered('visible') | 173 return repo.filtered('visible') |