mercurial/localrepo.py
changeset 32371 7aa4a4cf0dde
parent 32354 9f35c7836f60
child 32389 9742f937c971
--- a/mercurial/localrepo.py	Fri May 19 12:35:14 2017 +0200
+++ b/mercurial/localrepo.py	Fri May 19 13:09:23 2017 +0200
@@ -1105,10 +1105,7 @@
                                **pycompat.strkwargs(hookargs))
             reporef()._afterlock(hook)
         tr.addfinalize('txnclose-hook', txnclosehook)
-        def warmscache(tr2):
-            repo = reporef()
-            repo.updatecaches(tr2)
-        tr.addpostclose('warms-cache', warmscache)
+        tr.addpostclose('warms-cache', self._buildcacheupdater(tr))
         def txnaborthook(tr2):
             """To be run if transaction is aborted
             """
@@ -1243,6 +1240,20 @@
         self.destroyed()
         return 0
 
+    def _buildcacheupdater(self, newtransaction):
+        """called during transaction to build the callback updating cache
+
+        Lives on the repository to help extension who might want to augment
+        this logic. For this purpose, the created transaction is passed to the
+        method.
+        """
+        # we must avoid cyclic reference between repo and transaction.
+        reporef = weakref.ref(self)
+        def updater(tr):
+            repo = reporef()
+            repo.updatecaches(tr)
+        return updater
+
     @unfilteredmethod
     def updatecaches(self, tr=None):
         """warm appropriate caches