Mercurial > hg
view mercurial/rewriteutil.py @ 39604:335ae4d0a552
bundlerepo: dynamically create repository type from base repository
Previously, bundlerepository inherited from localrepo.localrepository.
You simply instantiated a bundlerepository and its __init__ called
localrepo.localrepository.__init__. Things were simple.
Unfortunately, this strategy is limiting because it assumes that
the base repository is a localrepository instance. And it assumes
various properties of localrepository, such as the arguments its
__init__ takes. And it prevents us from changing behavior of
localrepository.__init__ without also having to change derived classes.
Previous and ongoing work to abstract storage revealed these
limitations.
This commit changes the initialization strategy of bundle repositories
to dynamically create a type to represent the repository. Instead of
a static type, we instantiate a new local repo instance via
localrepo.instance(). We then combine its __class__ with
bundlerepository to produce a new type. This ensures that no matter
how localrepo.instance() decides to create a repository object, we
can derive a bundle repo object from it. i.e. localrepo.instance()
could return a type that isn't a localrepository and it would "just
work."
Well, it would "just work" if bundlerepository's custom implementations
only accessed attributes in the documented repository interface. I'm
pretty sure it violates the interface contract in a handful of
places. But we can worry about that another day. This change gets us
closer to doing more clever things around instantiating repository
instances without having to worry about teaching bundlerepository about
them.
.. api::
``bundlerepo.bundlerepository`` is no longer usable on its own.
The class is combined with the class of the base repository it is
associated with at run-time.
New bundlerepository instances can be obtained by calling
``bundlerepo.instance()`` or ``bundlerepo.makebundlerepository()``.
Differential Revision: https://phab.mercurial-scm.org/D4555
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 11 Sep 2018 19:50:07 -0700 |
parents | 490df753894d |
children | 8c6329fa6038 |
line wrap: on
line source
# rewriteutil.py - utility functions for rewriting changesets # # Copyright 2017 Octobus <contact@octobus.net> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import absolute_import from .i18n import _ from . import ( error, node, obsolete, revset, ) def precheck(repo, revs, action='rewrite'): """check if revs can be rewritten action is used to control the error message. Make sure this function is called after taking the lock. """ if node.nullrev in revs: msg = _("cannot %s null changeset") % (action) hint = _("no changeset checked out") raise error.Abort(msg, hint=hint) publicrevs = repo.revs('%ld and public()', revs) if len(repo[None].parents()) > 1: raise error.Abort(_("cannot %s while merging") % action) if publicrevs: msg = _("cannot %s public changesets") % (action) hint = _("see 'hg help phases' for details") raise error.Abort(msg, hint=hint) newunstable = disallowednewunstable(repo, revs) if newunstable: raise error.Abort(_("cannot %s changeset with children") % action) def disallowednewunstable(repo, revs): """Checks whether editing the revs will create new unstable changesets and are we allowed to create them. To allow new unstable changesets, set the config: `experimental.evolution.allowunstable=True` """ allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) if allowunstable: return revset.baseset() return repo.revs("(%ld::) - %ld", revs, revs)