changeset 2224:49776d324d1a

depth: add a utility function to access the cache This is preparing on disk persistence for the value in this cache.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 24 Mar 2017 09:01:25 +0100
parents 2ba541e1ea01
children 81f5ebd9e9d0
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Fri Mar 24 03:20:29 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Fri Mar 24 09:01:25 2017 +0100
@@ -224,13 +224,13 @@
     def depthrev(self, repo, rev):
         repo = repo.unfiltered()
         cl = repo.changelog
-        cache = self._depthcache
+        depth = self._getdepth
         nullrev = nodemod.nullrev
         stack = [rev]
         while stack:
             revdepth = None
             current = stack[-1]
-            revdepth = cache.get(current)
+            revdepth = depth(current)
             if revdepth is not None:
                 stack.pop()
                 continue
@@ -240,16 +240,16 @@
                 revdepth = 1
             elif p2 == nullrev:
                 # linear commit case
-                parentdepth = cache.get(p1)
+                parentdepth = depth(p1)
                 if parentdepth is None:
                     stack.append(p1)
                 else:
                     revdepth = parentdepth + 1
             else:
                 # merge case
-                revdepth = self._depthmerge(cl, current, p1, p2, stack, cache)
+                revdepth = self._depthmerge(cl, current, p1, p2, stack)
             if revdepth is not None:
-                cache[current] = revdepth
+                self._depthcache[current] = revdepth
                 stack.pop()
         # actual_depth = len(list(cl.ancestors([rev], inclusive=True)))
         # assert revdepth == actual_depth, (rev, revdepth, actual_depth)
@@ -298,6 +298,12 @@
             self._parentscache[rev] = parents
         return parents
 
+    def _getdepth(self, rev):
+        """utility function used to access the depth cache
+
+        This mostly exist to help the on disk persistence."""
+        return self._depthcache.get(rev)
+
     def _filestablesortcache(self, sortedrevs, merge):
         if merge not in self._stablesortprepared:
             self._stablesortprepared[merge] = (sortedrevs, len(sortedrevs))
@@ -360,12 +366,12 @@
             self._inheritancecache[merge] = value
         return value
 
-    @staticmethod
-    def _depthmerge(cl, rev, p1, p2, stack, cache):
+    def _depthmerge(self, cl, rev, p1, p2, stack):
         # sub method to simplify the main 'depthrev' one
         revdepth = None
-        depth_p1 = cache.get(p1)
-        depth_p2 = cache.get(p2)
+        depth = self._getdepth
+        depth_p1 = depth(p1)
+        depth_p2 = depth(p2)
         missingparent = False
         if depth_p1 is None:
             stack.append(p1)
@@ -382,7 +388,7 @@
         anyunkown = False
         ancdepth = []
         for r in ancrevs:
-            d = cache.get(r)
+            d = depth(r)
             if d is None:
                 anyunkown = True
                 stack.append(r)