##// END OF EJS Templates
hg: allow extra arguments to be passed to repo creation (API)...
Gregory Szorc -
r39585:089fc0db default
parent child Browse files
Show More
@@ -78,9 +78,10 b' class ShortRepository(object):'
78 def __repr__(self):
78 def __repr__(self):
79 return '<ShortRepository: %s>' % self.scheme
79 return '<ShortRepository: %s>' % self.scheme
80
80
81 def instance(self, ui, url, create, intents=None):
81 def instance(self, ui, url, create, intents=None, createopts=None):
82 url = self.resolve(url)
82 url = self.resolve(url)
83 return hg._peerlookup(url).instance(ui, url, create, intents=intents)
83 return hg._peerlookup(url).instance(ui, url, create, intents=intents,
84 createopts=createopts)
84
85
85 def resolve(self, url):
86 def resolve(self, url):
86 # Should this use the util.url class, or is manual parsing better?
87 # Should this use the util.url class, or is manual parsing better?
@@ -449,7 +449,7 b' class bundlerepository(localrepo.localre'
449 self.ui.warn(msg % nodemod.hex(p2))
449 self.ui.warn(msg % nodemod.hex(p2))
450 return super(bundlerepository, self).setparents(p1, p2)
450 return super(bundlerepository, self).setparents(p1, p2)
451
451
452 def instance(ui, path, create, intents=None):
452 def instance(ui, path, create, intents=None, createopts=None):
453 if create:
453 if create:
454 raise error.Abort(_('cannot create new bundle repository'))
454 raise error.Abort(_('cannot create new bundle repository'))
455 # internal config: bundle.mainreporoot
455 # internal config: bundle.mainreporoot
@@ -158,9 +158,10 b' def openpath(ui, path):'
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: ',
@@ -184,20 +185,22 b' def _peerorrepo(ui, path, create=False, '
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
@@ -982,7 +982,7 b' def makepeer(ui, path, opener=None, requ'
982 return httppeer(ui, path, respurl, opener, requestbuilder,
982 return httppeer(ui, path, respurl, opener, requestbuilder,
983 info['v1capabilities'])
983 info['v1capabilities'])
984
984
985 def instance(ui, path, create, intents=None):
985 def instance(ui, path, create, intents=None, createopts=None):
986 if create:
986 if create:
987 raise error.Abort(_('cannot create new http repository'))
987 raise error.Abort(_('cannot create new http repository'))
988 try:
988 try:
@@ -2380,26 +2380,28 b' def undoname(fn):'
2380 assert name.startswith('journal')
2380 assert name.startswith('journal')
2381 return os.path.join(base, name.replace('journal', 'undo', 1))
2381 return os.path.join(base, name.replace('journal', 'undo', 1))
2382
2382
2383 def instance(ui, path, create, intents=None):
2383 def instance(ui, path, create, intents=None, createopts=None):
2384 if create:
2384 if create:
2385 vfs = vfsmod.vfs(path, expandpath=True, realpath=True)
2385 vfs = vfsmod.vfs(path, expandpath=True, realpath=True)
2386
2386
2387 if vfs.exists('.hg'):
2387 if vfs.exists('.hg'):
2388 raise error.RepoError(_('repository %s already exists') % path)
2388 raise error.RepoError(_('repository %s already exists') % path)
2389
2389
2390 createrepository(ui, vfs)
2390 createrepository(ui, vfs, createopts=createopts)
2391
2391
2392 return localrepository(ui, util.urllocalpath(path), intents=intents)
2392 return localrepository(ui, util.urllocalpath(path), intents=intents)
2393
2393
2394 def islocal(path):
2394 def islocal(path):
2395 return True
2395 return True
2396
2396
2397 def newreporequirements(ui):
2397 def newreporequirements(ui, createopts=None):
2398 """Determine the set of requirements for a new local repository.
2398 """Determine the set of requirements for a new local repository.
2399
2399
2400 Extensions can wrap this function to specify custom requirements for
2400 Extensions can wrap this function to specify custom requirements for
2401 new repositories.
2401 new repositories.
2402 """
2402 """
2403 createopts = createopts or {}
2404
2403 requirements = {'revlogv1'}
2405 requirements = {'revlogv1'}
2404 if ui.configbool('format', 'usestore'):
2406 if ui.configbool('format', 'usestore'):
2405 requirements.add('store')
2407 requirements.add('store')
@@ -2440,13 +2442,43 b' def newreporequirements(ui):'
2440
2442
2441 return requirements
2443 return requirements
2442
2444
2443 def createrepository(ui, wdirvfs):
2445 def filterknowncreateopts(ui, createopts):
2446 """Filters a dict of repo creation options against options that are known.
2447
2448 Receives a dict of repo creation options and returns a dict of those
2449 options that we don't know how to handle.
2450
2451 This function is called as part of repository creation. If the
2452 returned dict contains any items, repository creation will not
2453 be allowed, as it means there was a request to create a repository
2454 with options not recognized by loaded code.
2455
2456 Extensions can wrap this function to filter out creation options
2457 they know how to handle.
2458 """
2459 return dict(createopts)
2460
2461 def createrepository(ui, wdirvfs, createopts=None):
2444 """Create a new repository in a vfs.
2462 """Create a new repository in a vfs.
2445
2463
2446 ``wdirvfs`` is a vfs instance pointing at the working directory.
2464 ``wdirvfs`` is a vfs instance pointing at the working directory.
2447 ``requirements`` is a set of requirements for the new repository.
2465 ``requirements`` is a set of requirements for the new repository.
2448 """
2466 """
2449 requirements = newreporequirements(ui)
2467 createopts = createopts or {}
2468
2469 unknownopts = filterknowncreateopts(ui, createopts)
2470
2471 if not isinstance(unknownopts, dict):
2472 raise error.ProgrammingError('filterknowncreateopts() did not return '
2473 'a dict')
2474
2475 if unknownopts:
2476 raise error.Abort(_('unable to create repository because of unknown '
2477 'creation option: %s') %
2478 ', '.sorted(unknownopts),
2479 hint=_('is a required extension not loaded?'))
2480
2481 requirements = newreporequirements(ui, createopts=createopts)
2450
2482
2451 if not wdirvfs.exists():
2483 if not wdirvfs.exists():
2452 wdirvfs.makedirs()
2484 wdirvfs.makedirs()
@@ -597,7 +597,7 b' def makepeer(ui, path, proc, stdin, stdo'
597 raise error.RepoError(_('unknown version of SSH protocol: %s') %
597 raise error.RepoError(_('unknown version of SSH protocol: %s') %
598 protoname)
598 protoname)
599
599
600 def instance(ui, path, create, intents=None):
600 def instance(ui, path, create, intents=None, createopts=None):
601 """Create an SSH peer.
601 """Create an SSH peer.
602
602
603 The returned object conforms to the ``wireprotov1peer.wirepeer`` interface.
603 The returned object conforms to the ``wireprotov1peer.wirepeer`` interface.
@@ -620,6 +620,14 b' def instance(ui, path, create, intents=N'
620 args = procutil.sshargs(sshcmd, u.host, u.user, u.port)
620 args = procutil.sshargs(sshcmd, u.host, u.user, u.port)
621
621
622 if create:
622 if create:
623 # We /could/ do this, but only if the remote init command knows how to
624 # handle them. We don't yet make any assumptions about that. And without
625 # querying the remote, there's no way of knowing if the remote even
626 # supports said requested feature.
627 if createopts:
628 raise error.RepoError(_('cannot create remote SSH repositories '
629 'with extra options'))
630
623 cmd = '%s %s %s' % (sshcmd, args,
631 cmd = '%s %s %s' % (sshcmd, args,
624 procutil.shellquote('%s init %s' %
632 procutil.shellquote('%s init %s' %
625 (_serverquote(remotecmd), _serverquote(remotepath))))
633 (_serverquote(remotecmd), _serverquote(remotepath))))
@@ -215,7 +215,7 b' class statichttprepository(localrepo.loc'
215 def _writecaches(self):
215 def _writecaches(self):
216 pass # statichttprepository are read only
216 pass # statichttprepository are read only
217
217
218 def instance(ui, path, create, intents=None):
218 def instance(ui, path, create, intents=None, createopts=None):
219 if create:
219 if create:
220 raise error.Abort(_('cannot create new static-http repository'))
220 raise error.Abort(_('cannot create new static-http repository'))
221 return statichttprepository(ui, path[7:])
221 return statichttprepository(ui, path[7:])
@@ -233,7 +233,7 b' class unionrepository(localrepo.localrep'
233 def getcwd(self):
233 def getcwd(self):
234 return pycompat.getcwd() # always outside the repo
234 return pycompat.getcwd() # always outside the repo
235
235
236 def instance(ui, path, create, intents=None):
236 def instance(ui, path, create, intents=None, createopts=None):
237 if create:
237 if create:
238 raise error.Abort(_('cannot create new union repository'))
238 raise error.Abort(_('cannot create new union repository'))
239 parentpath = ui.config("bundle", "mainreporoot")
239 parentpath = ui.config("bundle", "mainreporoot")
General Comments 0
You need to be logged in to leave comments. Login now