--- a/hgext3rd/evolve/obscache.py Fri May 12 18:34:37 2017 +0200
+++ b/hgext3rd/evolve/obscache.py Fri May 12 18:52:59 2017 +0200
@@ -88,62 +88,6 @@
emptykey = (node.nullrev, node.nullid, 0, 0, node.nullid)
-def upgradeneeded(repo, key):
- """return (valid, start-rev, start-obs-idx)
-
- 'valid': is "False" if older cache value needs invalidation,
-
- 'start-rev': first revision not in the cache. None if cache is up to date,
-
- 'start-obs-idx': index of the first obs-markers not in the cache. None is
- up to date.
- """
-
- # We need to ensure we use the same changelog and obsstore through the
- # processing. Otherwise some invalidation could update the object and their
- # content after we computed the cache key.
- cl = repo.changelog
- obsstore = repo.obsstore
-
- reset = False
-
- status = _checkkey(cl, obsstore, key)
- if status is None:
- reset = True
- key = emptykey
- obssize, obskey = obsstore.cachekey()
- tiprev = len(cl) - 1
- else:
- tiprev, obssize, obskey = status
-
- keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
-
- if not reset and keytiprev == tiprev and keyobssize == obssize:
- return None # nothing to upgrade
-
- ### cache is valid, is there anything to update
-
- # any new changesets ?
- revs = ()
- if keytiprev < tiprev:
- revs = list(cl.revs(start=keytiprev + 1, stop=tiprev))
-
- # any new markers
- markers = ()
- if keyobssize < obssize:
- # XXX Three are a small race change here. Since the obsstore might have
- # move forward between the time we computed the cache key and we access
- # the data. To fix this we need so "up to" argument when fetching the
- # markers here. Otherwise we might return more markers than covered by
- # the cache key.
- #
- # In pratice the cache is only updated after each transaction within a
- # lock. So we should be fine. We could enforce this with a new repository
- # requirement (or fix the race, that is not too hard).
- markers = markersfrom(obsstore, keyobssize, keyobslength)
-
- return reset, revs, markers, (obssize, obskey)
-
def _checkkey(changelog, obsstore, key):
"""internal function"""
if key is None:
@@ -261,6 +205,63 @@
and status[0] == self._cachekey[0] # tiprev
and status[1] == self._cachekey[3]) # obssize
+ def upgradeneeded(self, repo):
+ """return (valid, start-rev, start-obs-idx)
+
+ 'valid': is "False" if older cache value needs invalidation,
+
+ 'start-rev': first revision not in the cache. None if cache is up to date,
+
+ 'start-obs-idx': index of the first obs-markers not in the cache. None is
+ up to date.
+ """
+
+ # We need to ensure we use the same changelog and obsstore through the
+ # processing. Otherwise some invalidation could update the object and their
+ # content after we computed the cache key.
+ cl = repo.changelog
+ obsstore = repo.obsstore
+ key = self._cachekey
+
+ reset = False
+
+ status = _checkkey(cl, obsstore, key)
+ if status is None:
+ reset = True
+ key = emptykey
+ obssize, obskey = obsstore.cachekey()
+ tiprev = len(cl) - 1
+ else:
+ tiprev, obssize, obskey = status
+
+ keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
+
+ if not reset and keytiprev == tiprev and keyobssize == obssize:
+ return None # nothing to upgrade
+
+ ### cache is valid, is there anything to update
+
+ # any new changesets ?
+ revs = ()
+ if keytiprev < tiprev:
+ revs = list(cl.revs(start=keytiprev + 1, stop=tiprev))
+
+ # any new markers
+ markers = ()
+ if keyobssize < obssize:
+ # XXX Three are a small race change here. Since the obsstore might have
+ # move forward between the time we computed the cache key and we access
+ # the data. To fix this we need so "up to" argument when fetching the
+ # markers here. Otherwise we might return more markers than covered by
+ # the cache key.
+ #
+ # In pratice the cache is only updated after each transaction within a
+ # lock. So we should be fine. We could enforce this with a new repository
+ # requirement (or fix the race, that is not too hard).
+ markers = markersfrom(obsstore, keyobssize, keyobslength)
+
+ return reset, revs, markers, (obssize, obskey)
+
def update(self, repo):
"""Iteratively update the cache with new repository data"""
# If we do not have any data, try loading from disk
@@ -270,7 +271,7 @@
assert repo.filtername is None
cl = repo.changelog
- upgrade = upgradeneeded(repo, self._cachekey)
+ upgrade = self.upgradeneeded(repo)
if upgrade is None:
return