repoview: separate cache hash computation from cache reading
authorStanislau Hlebik <stash@fb.com>
Mon, 20 Feb 2017 01:54:07 -0800
changeset 31049 20027be9f23d
parent 31048 23bcfdd76f96
child 31050 206532700213
repoview: separate cache hash computation from cache reading This change will make it easier for extensions to use another cache hash.
mercurial/repoview.py
--- a/mercurial/repoview.py	Mon Feb 20 18:27:29 2017 +0100
+++ b/mercurial/repoview.py	Mon Feb 20 01:54:07 2017 -0800
@@ -139,15 +139,13 @@
         if wlock:
             wlock.release()
 
-def tryreadcache(repo, hideable):
-    """read a cache if the cache exists and is valid, otherwise returns None."""
+def _readhiddencache(repo, cachefilename, newhash):
     hidden = fh = None
     try:
         if repo.vfs.exists(cachefile):
             fh = repo.vfs.open(cachefile, 'rb')
             version, = struct.unpack(">H", fh.read(2))
             oldhash = fh.read(20)
-            newhash = cachehash(repo, hideable)
             if (cacheversion, oldhash) == (version, newhash):
                 # cache is valid, so we can start reading the hidden revs
                 data = fh.read()
@@ -165,6 +163,11 @@
         if fh:
             fh.close()
 
+def tryreadcache(repo, hideable):
+    """read a cache if the cache exists and is valid, otherwise returns None."""
+    newhash = cachehash(repo, hideable)
+    return _readhiddencache(repo, cachefile, newhash)
+
 def computehidden(repo):
     """compute the set of hidden revision to filter