localrepo: capture repo interface factory functions as lambas
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 01 Oct 2018 09:05:40 -0700
changeset 39994 6962ebc8f817
parent 39993 cd5f2e615262
child 39995 582676acaf6d
localrepo: capture repo interface factory functions as lambas Previously, the list would hold a reference to the original function and attempting to wrap the module function via extension wouldn't result in the wrapped function being called, completely undermining the expected behavior. Differential Revision: https://phab.mercurial-scm.org/D4821
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Mon May 14 00:43:07 2018 +0200
+++ b/mercurial/localrepo.py	Mon Oct 01 09:05:40 2018 -0700
@@ -534,7 +534,7 @@
     for iface, fn in REPO_INTERFACES:
         # We pass all potentially useful state to give extensions tons of
         # flexibility.
-        typ = fn(ui=ui,
+        typ = fn()(ui=ui,
                  intents=intents,
                  requirements=requirements,
                  features=features,
@@ -803,10 +803,12 @@
 
 # List of repository interfaces and factory functions for them. Each
 # will be called in order during ``makelocalrepository()`` to iteratively
-# derive the final type for a local repository instance.
+# derive the final type for a local repository instance. We capture the
+# function as a lambda so we don't hold a reference and the module-level
+# functions can be wrapped.
 REPO_INTERFACES = [
-    (repository.ilocalrepositorymain, makemain),
-    (repository.ilocalrepositoryfilestorage, makefilestorage),
+    (repository.ilocalrepositorymain, lambda: makemain),
+    (repository.ilocalrepositoryfilestorage, lambda: makefilestorage),
 ]
 
 @interfaceutil.implementer(repository.ilocalrepositorymain)