# HG changeset patch # User Pierre-Yves David # Date 1494608202 -7200 # Node ID dd8471e547089fca337d68d19c08cc5d81d64ea7 # Parent 1bec5ee9967408db7be078dc2b13a5bb5811fcad obcache: move _checkkey on the class We'll extract a smaller data agnostic class but we need to gather all method on it first. diff -r 1bec5ee99674 -r dd8471e54708 hgext3rd/evolve/obscache.py --- 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