obcache: move _checkkey on the class
We'll extract a smaller data agnostic class but we need to gather all method on
it first.
--- a/hgext3rd/evolve/obscache.py Fri May 12 18:52:59 2017 +0200
+++ b/hgext3rd/evolve/obscache.py Fri May 12 18:56:42 2017 +0200
@@ -88,24 +88,6 @@
emptykey = (node.nullrev, node.nullid, 0, 0, node.nullid)
-def _checkkey(changelog, obsstore, key):
- """internal function"""
- if key is None:
- return None
-
- ### Is the cache valid ?
- keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
- # check for changelog strip
- tiprev = len(changelog) - 1
- if (tiprev < keytiprev
- or changelog.node(keytiprev) != keytipnode):
- return None
- # check for obsstore strip
- obssize, obskey = obsstore.cachekey(index=keyobssize)
- if obskey != keyobskey:
- return None
- return tiprev, obssize, obskey
-
# XXX copied as is from Mercurial 4.2 and added the "offset" parameters
@util.nogc
def _readmarkers(data, offset=None):
@@ -197,10 +179,29 @@
self._cachekey = emptykey if reset else None
self._data = bytearray()
+ def _checkkey(self, changelog, obsstore):
+ """internal function"""
+ key = self._cachekey
+ if key is None:
+ return None
+
+ ### Is the cache valid ?
+ keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key
+ # check for changelog strip
+ tiprev = len(changelog) - 1
+ if (tiprev < keytiprev
+ or changelog.node(keytiprev) != keytipnode):
+ return None
+ # check for obsstore strip
+ obssize, obskey = obsstore.cachekey(index=keyobssize)
+ if obskey != keyobskey:
+ return None
+ return tiprev, obssize, obskey
+
def uptodate(self, repo):
if self._cachekey is None:
self.load(repo)
- status = _checkkey(repo.changelog, repo.obsstore, self._cachekey)
+ status = self._checkkey(repo.changelog, repo.obsstore)
return (status is not None
and status[0] == self._cachekey[0] # tiprev
and status[1] == self._cachekey[3]) # obssize
@@ -225,7 +226,7 @@
reset = False
- status = _checkkey(cl, obsstore, key)
+ status = self._checkkey(cl, obsstore)
if status is None:
reset = True
key = emptykey