changeset 2334:aac765e84de3

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).
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 24 Mar 2017 15:56:57 +0100
parents 98e0369b548b
children f4f6ff874c40
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py
+++ b/hgext3rd/evolve/stablerange.py
@@ -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