Patchwork repoview: separate cache hash computation from cache reading

login
register
mail settings
Submitter Stanislau Hlebik
Date Feb. 20, 2017, 9:56 a.m.
Message ID <cb1151ce14f7ec9e2ca9.1487584579@devvm1840.lla2.facebook.com>
Download mbox | patch
Permalink /patch/18681/
State Accepted
Headers show

Comments

Stanislau Hlebik - Feb. 20, 2017, 9:56 a.m.
# HG changeset patch
# User Stanislau Hlebik <stash@fb.com>
# Date 1487584447 28800
#      Mon Feb 20 01:54:07 2017 -0800
# Node ID cb1151ce14f7ec9e2ca991bc8bd590020ec4b061
# Parent  693a5bb478543a986808264e586073a3ceedc38f
repoview: separate cache hash computation from cache reading

This change will make it easier for extensions to use another cache hash.
Augie Fackler - Feb. 21, 2017, 4:09 p.m.
On Mon, Feb 20, 2017 at 01:56:19AM -0800, Stanislau Hlebik wrote:
> # HG changeset patch
> # User Stanislau Hlebik <stash@fb.com>
> # Date 1487584447 28800
> #      Mon Feb 20 01:54:07 2017 -0800
> # Node ID cb1151ce14f7ec9e2ca991bc8bd590020ec4b061
> # Parent  693a5bb478543a986808264e586073a3ceedc38f
> repoview: separate cache hash computation from cache reading

Seems harmless enough, queued. Thanks.

>
> This change will make it easier for extensions to use another cache hash.
>
> diff --git a/mercurial/repoview.py b/mercurial/repoview.py
> --- a/mercurial/repoview.py
> +++ b/mercurial/repoview.py
> @@ -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
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -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