This is an archive of the discontinued Mercurial Phabricator instance.

localrepo: extract resolving of opener options to standalone functions
ClosedPublic

Authored by indygreg on Sep 13 2018, 12:29 PM.

Details

Summary

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.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Sep 13 2018, 12:29 PM

I kind of hope that eventually you're going to break all the requirements-handling nonsense out into its own module somehow?

This revision was automatically updated to reflect the committed changes.

I kind of hope that eventually you're going to break all the requirements-handling nonsense out into its own module somehow?

I suspect I'm trending in the direction of creating a storage module/package to hold all things storage. I would like to e.g. isolate code for revlog-based repositories from other backends from generic, storage-agnostic code. Right now, it's definitely easier to keep things in localrepo.py until we're closer to that future world. But a few more series like this and we may be close enough...