# HG changeset patch # User Pierre-Yves David # Date 2017-05-19 11:09:23 # Node ID 7aa4a4cf0dde3a051990238be4e70ba18d45f7d7 # Parent 8fb5f452e69ce684a4a1b7b5d151a043222710db 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. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1105,10 +1105,7 @@ class localrepository(object): **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 @@ class localrepository(object): 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