[PATCH 01 of 10] localrepo: add a baselocalrepository class
Jun Wu
quark at fb.com
Fri Feb 10 01:46:15 UTC 2017
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1486673958 28800
# Thu Feb 09 12:59:18 2017 -0800
# Node ID bdaf60a60f81431a52291ece25ad3cd60c77ac05
# Parent a68510b69f413545722c086eaeb840dd5e8305b4
# Available At https://bitbucket.org/quark-zju/hg-draft
# hg pull https://bitbucket.org/quark-zju/hg-draft -r bdaf60a60f81
localrepo: add a baselocalrepository class
The chg repo preloading logic [1] requires a side-effect-free repo object.
Currently localrepository.__init__ has too many side-effects (loading
extensions, running setups). So add a new class without the effects.
The newly added repo class is incomplete, follow-up patches will move more
methods to it.
[1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-February/092547.html
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -237,5 +237,27 @@ class locallegacypeer(localpeer):
return changegroup.changegroupsubset(self._repo, bases, heads, source)
-class localrepository(object):
+class baselocalrepository(object):
+ """like localrepository, but without side effects
+
+ Side effects are like loading extensions, running setup functions, locking
+ the repo or writing to something that changes the repo content, etc.
+
+ It's basically a limited read-only repo object that provides very basic
+ access tools to repo content like vfs, svfs. It's useful for chg to preload
+ repo states, without causing unwanted effects.
+ """
+ def __init__(self, baseui, path):
+ self.requirements = set()
+ self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True)
+ self.wopener = self.wvfs
+ self.root = self.wvfs.base
+ self.path = self.wvfs.join(".hg")
+ self.origroot = path
+ self.vfs = scmutil.vfs(self.path)
+ self.opener = self.vfs
+
+ self.baseui = baseui
+
+class localrepository(baselocalrepository):
supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest',
@@ -251,16 +273,8 @@ class localrepository(object):
def __init__(self, baseui, path, create=False):
- self.requirements = set()
- self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True)
- self.wopener = self.wvfs
- self.root = self.wvfs.base
- self.path = self.wvfs.join(".hg")
- self.origroot = path
+ super(localrepository, self).__init__(baseui, path)
self.auditor = pathutil.pathauditor(self.root, self._checknested)
self.nofsauditor = pathutil.pathauditor(self.root, self._checknested,
realfs=False)
- self.vfs = scmutil.vfs(self.path)
- self.opener = self.vfs
- self.baseui = baseui
self.ui = baseui.copy()
self.ui.copy = baseui.copy # prevent copying repo configuration
More information about the Mercurial-devel
mailing list