comparison mercurial/hg.py @ 39549:089fc0db0954

hg: allow extra arguments to be passed to repo creation (API) Currently, repository creation is influenced by consulting the ui instance and turning config options into requirements. This means that in order to influence repository creation, you need to define and set a config option and that the option must translate to a requirement stored in the .hg/requires file. This commit introduces a new mechanism to influence repository creation. hg.repository() and hg.peer() have been taught to receive a new optional argument defining extra options to apply to repository creation. This value is passed along to the various instance() functions and can be used to influence repository creation. This will allow us to pass rich data directly to repository creation without having to go through the config layer. It also allows us to be more explicit about the features requested during repository creation and provides a natural point to detect unhandled options influencing repository creation. The new code detects when unknown creation options are present and aborts in that case. .. api:: options can now be passed to influence repository creation The various instance() functions to spawn new peers or repository instances now receive a ``createopts`` argument that can be a dict defining additional options to influence repository creation. localrepo.newreporequirements() also receives this argument. Differential Revision: https://phab.mercurial-scm.org/D4535
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 11 Sep 2018 17:11:32 -0700
parents 340170192874
children 65b5900f30be
comparison
equal deleted inserted replaced
39548:7ce9dea3a14a 39549:089fc0db0954
156 156
157 # a list of (ui, repo) functions called for wire peer initialization 157 # a list of (ui, repo) functions called for wire peer initialization
158 wirepeersetupfuncs = [] 158 wirepeersetupfuncs = []
159 159
160 def _peerorrepo(ui, path, create=False, presetupfuncs=None, 160 def _peerorrepo(ui, path, create=False, presetupfuncs=None,
161 intents=None): 161 intents=None, createopts=None):
162 """return a repository object for the specified path""" 162 """return a repository object for the specified path"""
163 obj = _peerlookup(path).instance(ui, path, create, intents=intents) 163 obj = _peerlookup(path).instance(ui, path, create, intents=intents,
164 createopts=createopts)
164 ui = getattr(obj, "ui", ui) 165 ui = getattr(obj, "ui", ui)
165 if ui.configbool('devel', 'debug.extensions'): 166 if ui.configbool('devel', 'debug.extensions'):
166 log = lambda msg, *values: ui.debug('debug.extensions: ', 167 log = lambda msg, *values: ui.debug('debug.extensions: ',
167 msg % values, label='debug.extensions') 168 msg % values, label='debug.extensions')
168 else: 169 else:
182 if not obj.local(): 183 if not obj.local():
183 for f in wirepeersetupfuncs: 184 for f in wirepeersetupfuncs:
184 f(ui, obj) 185 f(ui, obj)
185 return obj 186 return obj
186 187
187 def repository(ui, path='', create=False, presetupfuncs=None, intents=None): 188 def repository(ui, path='', create=False, presetupfuncs=None, intents=None,
189 createopts=None):
188 """return a repository object for the specified path""" 190 """return a repository object for the specified path"""
189 peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs, 191 peer = _peerorrepo(ui, path, create, presetupfuncs=presetupfuncs,
190 intents=intents) 192 intents=intents, createopts=createopts)
191 repo = peer.local() 193 repo = peer.local()
192 if not repo: 194 if not repo:
193 raise error.Abort(_("repository '%s' is not local") % 195 raise error.Abort(_("repository '%s' is not local") %
194 (path or peer.url())) 196 (path or peer.url()))
195 return repo.filtered('visible') 197 return repo.filtered('visible')
196 198
197 def peer(uiorrepo, opts, path, create=False, intents=None): 199 def peer(uiorrepo, opts, path, create=False, intents=None, createopts=None):
198 '''return a repository peer for the specified path''' 200 '''return a repository peer for the specified path'''
199 rui = remoteui(uiorrepo, opts) 201 rui = remoteui(uiorrepo, opts)
200 return _peerorrepo(rui, path, create, intents=intents).peer() 202 return _peerorrepo(rui, path, create, intents=intents,
203 createopts=createopts).peer()
201 204
202 def defaultdest(source): 205 def defaultdest(source):
203 '''return default destination of clone if none is given 206 '''return default destination of clone if none is given
204 207
205 >>> defaultdest(b'foo') 208 >>> defaultdest(b'foo')