stablerange: warm cache on transaction (if obshashrange is enabled)
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 24 Mar 2017 15:56:57 +0100
changeset 2238 aac765e84de3
parent 2237 98e0369b548b
child 2239 f4f6ff874c40
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).
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