Mercurial > public > mercurial-scm > hg
comparison mercurial/streamclone.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 | 97f2992c26f6 |
comparison
equal
deleted
inserted
replaced
39699:6f26417b71bb | 39700:b10d145837bc |
---|---|
112 operations. | 112 operations. |
113 | 113 |
114 A legacy stream clone will not be performed if a bundle2 stream clone is | 114 A legacy stream clone will not be performed if a bundle2 stream clone is |
115 supported. | 115 supported. |
116 """ | 116 """ |
117 from . import localrepo | |
118 | |
117 supported, requirements = canperformstreamclone(pullop) | 119 supported, requirements = canperformstreamclone(pullop) |
118 | 120 |
119 if not supported: | 121 if not supported: |
120 return | 122 return |
121 | 123 |
164 # new requirements = old non-format requirements + | 166 # new requirements = old non-format requirements + |
165 # new format-related remote requirements | 167 # new format-related remote requirements |
166 # requirements from the streamed-in repository | 168 # requirements from the streamed-in repository |
167 repo.requirements = requirements | ( | 169 repo.requirements = requirements | ( |
168 repo.requirements - repo.supportedformats) | 170 repo.requirements - repo.supportedformats) |
169 repo._applyopenerreqs() | 171 repo.svfs.options = localrepo.resolvestorevfsoptions( |
172 repo.ui, repo.requirements) | |
170 repo._writerequirements() | 173 repo._writerequirements() |
171 | 174 |
172 if rbranchmap: | 175 if rbranchmap: |
173 branchmap.replacecache(repo, rbranchmap) | 176 branchmap.replacecache(repo, rbranchmap) |
174 | 177 |
622 (util.bytecount(progress.pos), elapsed, | 625 (util.bytecount(progress.pos), elapsed, |
623 util.bytecount(progress.pos / elapsed))) | 626 util.bytecount(progress.pos / elapsed))) |
624 progress.complete() | 627 progress.complete() |
625 | 628 |
626 def applybundlev2(repo, fp, filecount, filesize, requirements): | 629 def applybundlev2(repo, fp, filecount, filesize, requirements): |
630 from . import localrepo | |
631 | |
627 missingreqs = [r for r in requirements if r not in repo.supported] | 632 missingreqs = [r for r in requirements if r not in repo.supported] |
628 if missingreqs: | 633 if missingreqs: |
629 raise error.Abort(_('unable to apply stream clone: ' | 634 raise error.Abort(_('unable to apply stream clone: ' |
630 'unsupported format: %s') % | 635 'unsupported format: %s') % |
631 ', '.join(sorted(missingreqs))) | 636 ', '.join(sorted(missingreqs))) |
635 # new requirements = old non-format requirements + | 640 # new requirements = old non-format requirements + |
636 # new format-related remote requirements | 641 # new format-related remote requirements |
637 # requirements from the streamed-in repository | 642 # requirements from the streamed-in repository |
638 repo.requirements = set(requirements) | ( | 643 repo.requirements = set(requirements) | ( |
639 repo.requirements - repo.supportedformats) | 644 repo.requirements - repo.supportedformats) |
640 repo._applyopenerreqs() | 645 repo.svfs.options = localrepo.resolvestorevfsoptions( |
646 repo.ui, repo.requirements) | |
641 repo._writerequirements() | 647 repo._writerequirements() |