# HG changeset patch # User Gregory Szorc # Date 2018-09-12 03:06:39 # Node ID 23f2299e9e536d7e74351547fc586c926a938375 # Parent 335ae4d0a5526e42ce3399158c14c6a4f45aa979 unionrepo: dynamically create repository type from base repository This is basically the same thing we just did for bundlerepo except for union repositories. .. api:: ``unionrepo.unionrepository()`` is no longer usable on its own. To instantiate an instance, call ``unionrepo.instance()`` or ``unionrepo.makeunionrepository()``. Differential Revision: https://phab.mercurial-scm.org/D4556 diff --git a/mercurial/unionrepo.py b/mercurial/unionrepo.py --- a/mercurial/unionrepo.py +++ b/mercurial/unionrepo.py @@ -192,15 +192,18 @@ class unionpeer(localrepo.localpeer): def canpush(self): return False -class unionrepository(localrepo.localrepository): - def __init__(self, ui, path, path2): - localrepo.localrepository.__init__(self, ui, path) +class unionrepository(object): + """Represents the union of data in 2 repositories. + + Instances are not usable if constructed directly. Use ``instance()`` + or ``makeunionrepository()`` to create a usable instance. + """ + def __init__(self, repo2, url): + self.repo2 = repo2 + self._url = url + self.ui.setconfig('phases', 'publish', False, 'unionrepo') - self._url = 'union:%s+%s' % (util.expandpath(path), - util.expandpath(path2)) - self.repo2 = localrepo.localrepository(ui, path2) - @localrepo.unfilteredpropertycache def changelog(self): return unionchangelog(self.svfs, self.repo2.svfs) @@ -260,4 +263,22 @@ def instance(ui, path, create, intents=N repopath, repopath2 = s else: repopath, repopath2 = parentpath, path - return unionrepository(ui, repopath, repopath2) + + return makeunionrepository(ui, repopath, repopath2) + +def makeunionrepository(ui, repopath1, repopath2): + """Make a union repository object from 2 local repo paths.""" + repo1 = localrepo.instance(ui, repopath1, create=False) + repo2 = localrepo.instance(ui, repopath2, create=False) + + url = 'union:%s+%s' % (util.expandpath(repopath1), + util.expandpath(repopath2)) + + class derivedunionrepository(unionrepository, repo1.__class__): + pass + + repo = repo1 + repo.__class__ = derivedunionrepository + unionrepository.__init__(repo1, repo2, url) + + return repo