# HG changeset patch # User Pierre-Yves David # Date 1490367417 -3600 # Node ID aac765e84de3fbae8ac3f65606511a47e5c5113f # Parent 98e0369b548be1b7409dc8175d4db90cdc010dcd stablerange: warm cache on transaction (if obshashrange is enabled) If we plan to use it (obshashrange is enabled) we better keep it up to date. If a transaction adds node, we update the cache (this should also update the on disk version). diff -r 98e0369b548b -r aac765e84de3 hgext3rd/evolve/stablerange.py --- a/hgext3rd/evolve/stablerange.py Fri Mar 24 16:05:28 2017 +0100 +++ b/hgext3rd/evolve/stablerange.py Fri Mar 24 15:56:57 2017 +0100 @@ -11,6 +11,7 @@ import heapq import math import sqlite3 +import weakref from mercurial import ( commands, @@ -885,4 +886,21 @@ if 'stablerange' in vars(self): del self.stablerange + def transaction(self, *args, **kwargs): + tr = super(stablerangerepo, self).transaction(*args, **kwargs) + if not repo.ui.configbool('experimental', 'obshashrange', False): + return tr + reporef = weakref.ref(self) + + def _warmcache(tr): + repo = reporef() + if repo is None: + return + if 'node' in tr.hookargs: + # new nodes ! + repo.stablerange.warmup(repo) + + tr.addpostclose('warmcache-stablerange', _warmcache) + return tr + repo.__class__ = stablerangerepo