[PATCH] localrepo: move extension loading to a separate method

Jun Wu quark at fb.com
Thu Feb 16 03:42:40 UTC 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1487216474 28800
#      Wed Feb 15 19:41:14 2017 -0800
# Node ID dda2ebe89f50fcf3bf5a9b8d2266aa2dd5b106ea
# Parent  e5363cb96233861fc99f7e9b85d7884d3121558c
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r dda2ebe89f50
localrepo: move extension loading to a separate method

The stateful chg plan [1] requires a special repo object, where ideally all
side effects caused by loading the repo object could be reverted by just
dropping (gabbage collect) the loaded repo object.

Currently, that is impossible because repo.__init__ calls
"extensions.loadall", which may have unpredictable side-effects that cannot
be reverted by dropping the repo object.

This patch moves "extensions.loadall" to a separate method, so chg could
subclass localrepository and make extensions loading a no-op.

[1]: 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
@@ -271,5 +271,5 @@ class localrepository(object):
         try:
             self.ui.readconfig(self.join("hgrc"), self.root)
-            extensions.loadall(self.ui)
+            self._loadextensions()
         except IOError:
             pass
@@ -372,4 +372,7 @@ class localrepository(object):
         self._writecaches()
 
+    def _loadextensions(self):
+        extensions.loadall(self.ui)
+
     def _writecaches(self):
         if self._revbranchcache:


More information about the Mercurial-devel mailing list