Mercurial > evolve
changeset 2343:37749a3cd3d1
obscache: extract the cache key validation in its own function
This help keep the "up to date logic" simpler and prepare a more complex
version of the "upgradeneeded" logic that would return the full data needed for
the upgrade.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 11 May 2017 16:05:50 +0200 |
parents | e28026b4d3c1 |
children | 827d0f0a483f |
files | hgext3rd/evolve/obscache.py |
diffstat | 1 files changed, 23 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obscache.py Wed May 10 11:52:11 2017 +0200 +++ b/hgext3rd/evolve/obscache.py Thu May 11 16:05:50 2017 +0200 @@ -109,22 +109,13 @@ # 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). - invalid = (False, 0, 0) - if key is None: - return invalid - ### Is the cache valid ? + status = _checkkey(repo, key) + if status is None: + return (False, 0, 0) + keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key - # check for changelog strip - cl = repo.changelog - tiprev = len(cl) - 1 - if (tiprev < keytiprev - or cl.node(keytiprev) != keytipnode): - return invalid - # check for obsstore strip - obssize, obskey = repo.obsstore.cachekey(index=keyobssize) - if obskey != keyobskey: - return invalid + tiprev, obssize, __ = status ### cache is valid, is there anything to update @@ -140,6 +131,24 @@ return True, startrev, startidx +def _checkkey(repo, key): + """internal function""" + if key is None: + return None + + ### Is the cache valid ? + keytiprev, keytipnode, keyobslength, keyobssize, keyobskey = key + # check for changelog strip + cl = repo.changelog + tiprev = len(cl) - 1 + if (tiprev < keytiprev + or cl.node(keytiprev) != keytipnode): + return None + # check for obsstore strip + obssize, obskey = repo.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