comparison mercurial/bundle2.py @ 39700:b10d145837bc

localrepo: extract resolving of opener options to standalone functions Requirements and config options are converted into a dict which is available to the store vfs to consult. This is how storage options are communicated from the repo layer to the storage layer. Currently, we do that option resolution in a private method on the repo instance. And there is a single method doing that resolution. Opener options are logically specific to the storage backend they apply to. And, opener options may wish to influence how the repo object/type is constructed. So it makes sense to have more granular storage option resolution that occurs before the repo object is instantiated. This commit extracts the code for resolving opener options into new module-level functions. These functions are run before the repo instance is constructed. As part of the code move, we split the option resolution into generic and revlog-specific options. After this commit, we no longer add revlog-specific options to repos that don't have a revlog requirement. Some of these opener options and associated config options might make sense on alternate storage backends. We can always reuse config options and opener option names for other backends. But we shouldn't be passing opener options to storage backends that won't recognize them. I haven't done it here, but after this commit it should be possible for store backends to validate the set of opener options it receives. Because localrepository.openerreqs is no longer used after this commit, it has been removed. I'm not super thrilled about the code outside of localrepo that is adding requirements and updating opener options. We'll probably want to create a more formal API for that use case that constructs a new repo instance and poisons the old repo object. But this was a pre-existing issue and can be dealt with later. I have little doubt it will cause me troubles as I continue to refactor how repository objects are instantiated. .. api:: ``localrepository.openerreqs`` has been removed. Override ``localrepo.resolvestorevfsoptions()`` to add custom opener options. .. api:: ``localrepository._applyopenerreqs()`` has been removed. Use ``localrepo.resolvestorevfsoptions()`` to add custom opener options. Differential Revision: https://phab.mercurial-scm.org/D4576
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 12 Sep 2018 15:59:26 -0700
parents e7aa113b14f7
children 1b5880352314
comparison
equal deleted inserted replaced
39699:6f26417b71bb 39700:b10d145837bc
1777 """apply a changegroup part on the repo 1777 """apply a changegroup part on the repo
1778 1778
1779 This is a very early implementation that will massive rework before being 1779 This is a very early implementation that will massive rework before being
1780 inflicted to any end-user. 1780 inflicted to any end-user.
1781 """ 1781 """
1782 from . import localrepo
1783
1782 tr = op.gettransaction() 1784 tr = op.gettransaction()
1783 unpackerversion = inpart.params.get('version', '01') 1785 unpackerversion = inpart.params.get('version', '01')
1784 # We should raise an appropriate exception here 1786 # We should raise an appropriate exception here
1785 cg = changegroup.getunbundler(unpackerversion, inpart, None) 1787 cg = changegroup.getunbundler(unpackerversion, inpart, None)
1786 # the source and url passed here are overwritten by the one contained in 1788 # the source and url passed here are overwritten by the one contained in
1793 if len(op.repo.changelog) != 0: 1795 if len(op.repo.changelog) != 0:
1794 raise error.Abort(_( 1796 raise error.Abort(_(
1795 "bundle contains tree manifests, but local repo is " 1797 "bundle contains tree manifests, but local repo is "
1796 "non-empty and does not use tree manifests")) 1798 "non-empty and does not use tree manifests"))
1797 op.repo.requirements.add('treemanifest') 1799 op.repo.requirements.add('treemanifest')
1798 op.repo._applyopenerreqs() 1800 op.repo.svfs.options = localrepo.resolvestorevfsoptions(
1801 op.repo.ui, op.repo.requirements)
1799 op.repo._writerequirements() 1802 op.repo._writerequirements()
1800 extrakwargs = {} 1803 extrakwargs = {}
1801 targetphase = inpart.params.get('targetphase') 1804 targetphase = inpart.params.get('targetphase')
1802 if targetphase is not None: 1805 if targetphase is not None:
1803 extrakwargs[r'targetphase'] = int(targetphase) 1806 extrakwargs[r'targetphase'] = int(targetphase)