hgext3rd/evolve/obscache.py
changeset 2334 b31ef65a846a
parent 2333 adf114c767ab
child 2343 37749a3cd3d1
--- a/hgext3rd/evolve/obscache.py	Tue May 09 19:02:04 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Tue May 09 19:13:12 2017 +0200
@@ -88,29 +88,6 @@
 
 emptykey = (node.nullrev, node.nullid, 0, 0, node.nullid)
 
-def getcachekey(repo):
-    """get a cache key covering the changesets and obsmarkers content
-
-    IT contains the following data. Combined with 'upgradeneeded' it allows to
-    do iterative upgrade for cache depending of theses two data.
-
-    The cache key parts are"
-    - tip-rev,
-    - tip-node,
-    - obsstore-length (nb markers),
-    - obsstore-file-size (in bytes),
-    - obsstore "cache key"
-    """
-    assert repo.filtername is None
-    cl = repo.changelog
-    index, key = repo.obsstore.cachekey()
-    tiprev = len(cl) - 1
-    return (tiprev,
-            cl.node(tiprev),
-            len(repo.obsstore),
-            index,
-            key)
-
 def upgradeneeded(repo, key):
     """return (valid, start-rev, start-obs-idx)
 
@@ -227,6 +204,11 @@
 
     def __init__(self, repo):
         self._vfs = repo.vfs
+        # cache key covering the changesets and obsmarkers content
+        #
+        # It contains the following data. Combined with 'upgradeneeded' it allows to
+        # do iterative upgrade for cache depending of theses two pieces of data.
+        #
         # The cache key parts are"
         # - tip-rev,
         # - tip-node,
@@ -292,7 +274,16 @@
                 markers = markersfrom(repo.obsstore, self._cachekey[3], startidx)
             self._updatemarkers(repo, markers)
 
-        self._cachekey = getcachekey(repo)
+        # update the key from the new data
+        key = list(self._cachekey)
+        if startrev is not None:
+            key[0] = len(cl) - 1
+            key[1] = cl.node(key[0])
+        if startidx is not None:
+            key[2] += len(markers)
+            # XXX still a small race here if repo is not locked
+            key[3], key[4] = repo.obsstore.cachekey()
+        self._cachekey = tuple(key)
 
     def _updaterevs(self, repo, revs):
         """update the cache with new revisions