changeset 32332:7aa4a4cf0dde

cache: make the cache updated callback easily accessible to extension This will help extension to benefit from this new logic. As a side effect this clarify the 'transaction' method a little bit.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 19 May 2017 13:09:23 +0200
parents 8fb5f452e69c
children 566cfe9cbbb9
files mercurial/localrepo.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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