changeset 3342:3194aec207ae

stablerange: add a base class for on disk stored stablerange class
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 18 Dec 2017 01:11:01 +0100
parents eadbe24a93f8
children 86a03229d32d
files hgext3rd/evolve/stablerangecache.py
diffstat 1 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerangecache.py	Thu Dec 21 02:13:19 2017 +0100
+++ b/hgext3rd/evolve/stablerangecache.py	Mon Dec 18 01:11:01 2017 +0100
@@ -1,5 +1,7 @@
 import abc
+import heapq
 import sqlite3
+import time
 import weakref
 
 from mercurial import (
@@ -10,6 +12,7 @@
 
 from . import (
     exthelper,
+    genericcaches,
     stablerange,
 )
 
@@ -17,6 +20,57 @@
 
 eh = exthelper.exthelper()
 eh.merge(stablerange.eh)
+
+class stablerangeondiskbase(stablerange.stablerangecached,
+                            genericcaches.changelogsourcebase):
+    """combine the generic stablerange cache usage with generic changelog one
+    """
+
+    def _updatefrom(self, repo, data):
+        """compute the rev of one revision, assert previous revision has an hot cache
+        """
+        repo = repo.unfiltered()
+        ui = repo.ui
+
+        rangeheap = []
+        for r in data:
+            rangeheap.append((r, 0))
+        total = len(data)
+
+        heappop = heapq.heappop
+        heappush = heapq.heappush
+        heapify = heapq.heapify
+
+        original = set(rangeheap)
+        seen = 0
+        # progress report is showing up in the profile for small and fast
+        # repository so we only update it every so often
+        progress_each = 100
+        progress_last = time.time()
+        heapify(rangeheap)
+        while rangeheap:
+            rangeid = heappop(rangeheap)
+            if rangeid in original:
+                if not seen % progress_each:
+                    # if a lot of time passed, report more often
+                    progress_new = time.time()
+                    if (1 < progress_each) and (0.1 < progress_new - progress_last):
+                        progress_each /= 10
+                    ui.progress(_("filling stablerange cache"), seen, total=total)
+                    progress_last = progress_new
+                seen += 1
+                original.remove(rangeid) # might have been added from other source
+            rangeid = rangeid
+            if self._getsub(rangeid) is None:
+                for sub in self.subranges(repo, rangeid):
+                    if self._getsub(sub) is None:
+                        heappush(rangeheap, sub)
+        ui.progress(_("filling stablerange cache"), None, total=total)
+
+    def clear(self, reset=False):
+        super(stablerangeondiskbase, self).clear()
+        self._subrangescache.clear()
+
 #############################
 ### simple sqlite caching ###
 #############################