Patchwork [4,of,6,V3] hidden: drop the hidden cache logic

login
register
mail settings
Submitter Pierre-Yves David
Date May 26, 2017, 6:34 p.m.
Message ID <548c9ad5d78f8b13dd60.1495823688@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20934/
State Accepted
Headers show

Comments

Pierre-Yves David - May 26, 2017, 6:34 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1495374788 -7200
#      Sun May 21 15:53:08 2017 +0200
# Node ID 548c9ad5d78f8b13dd60eea6ae0abba80ccf0349
# Parent  cfd0735170e8ef4d5913f8dd0a9864f9c13bfd28
# EXP-Topic fast-compute-hidden
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 548c9ad5d78f
hidden: drop the hidden cache logic

The improvement in time complexitty and the speed-up in computation is large
enough that the has little use now. Its update time can even gets in the way. So
we drop it.

This will allow us to unify the static/dynamic blockers logic in the next
changeset.

Patch

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -9,12 +9,9 @@ 
 from __future__ import absolute_import
 
 import copy
-import hashlib
-import struct
 
 from .node import nullrev
 from . import (
-    error,
     obsolete,
     phases,
     tags as tagsmod,
@@ -126,82 +123,6 @@  def _domainancestors(pfunc, revs, domain
                 stack.append(p)
     return ancestors
 
-cacheversion = 1
-cachefile = 'cache/hidden'
-
-def cachehash(repo, hideable):
-    """return sha1 hash of repository data to identify a valid cache.
-
-    We calculate a sha1 of repo heads and the content of the obsstore and write
-    it to the cache. Upon reading we can easily validate by checking the hash
-    against the stored one and discard the cache in case the hashes don't match.
-    """
-    h = hashlib.sha1()
-    h.update(''.join(repo.heads()))
-    h.update('%d' % hash(frozenset(hideable)))
-    return h.digest()
-
-def _writehiddencache(cachefile, cachehash, hidden):
-    """write hidden data to a cache file"""
-    data = struct.pack('>%ii' % len(hidden), *sorted(hidden))
-    cachefile.write(struct.pack(">H", cacheversion))
-    cachefile.write(cachehash)
-    cachefile.write(data)
-
-def trywritehiddencache(repo, hideable, hidden):
-    """write cache of hidden changesets to disk
-
-    Will not write the cache if a wlock cannot be obtained lazily.
-    The cache consists of a head of 22byte:
-       2 byte    version number of the cache
-      20 byte    sha1 to validate the cache
-     n*4 byte    hidden revs
-    """
-    wlock = fh = None
-    try:
-        wlock = repo.wlock(wait=False)
-        # write cache to file
-        newhash = cachehash(repo, hideable)
-        fh = repo.vfs.open(cachefile, 'w+b', atomictemp=True)
-        _writehiddencache(fh, newhash, hidden)
-        fh.close()
-    except (IOError, OSError):
-        repo.ui.debug('error writing hidden changesets cache\n')
-    except error.LockHeld:
-        repo.ui.debug('cannot obtain lock to write hidden changesets cache\n')
-    finally:
-        if wlock:
-            wlock.release()
-
-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)
-            if (cacheversion, oldhash) == (version, newhash):
-                # cache is valid, so we can start reading the hidden revs
-                data = fh.read()
-                count = len(data) / 4
-                hidden = frozenset(struct.unpack('>%ii' % count, data))
-        return hidden
-    except struct.error:
-        repo.ui.debug('corrupted hidden cache\n')
-        # No need to fix the content as it will get rewritten
-        return None
-    except (IOError, OSError):
-        repo.ui.debug('cannot read hidden cache\n')
-        return None
-    finally:
-        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
 
@@ -212,10 +133,7 @@  def computehidden(repo):
     hideable = hideablerevs(repo)
     if hideable:
         cl = repo.changelog
-        hidden = tryreadcache(repo, hideable)
-        if hidden is None:
-            hidden = frozenset(_getstatichidden(repo))
-            trywritehiddencache(repo, hideable, hidden)
+        hidden = frozenset(_getstatichidden(repo))
 
         # check if we have wd parents, bookmarks or tags pointing to hidden
         # changesets and remove those.
diff --git a/tests/test-cache-abuse.t b/tests/test-cache-abuse.t
--- a/tests/test-cache-abuse.t
+++ b/tests/test-cache-abuse.t
@@ -70,10 +70,6 @@  Beat up tags caches:
   $ damage tags tags2-visible
   $ damage "tag -f t3" hgtagsfnodes1
 
-Beat up hidden cache:
-
-  $ damage log hidden
-
 Beat up branch caches:
 
   $ damage branches branch2-base "rm .hg/cache/branch2-[vs]*"
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1093,25 +1093,6 @@  Test heads computation on pending index 
   $ hg amendtransient
   [1, 3]
 
-Check that corrupted hidden cache does not crash
-
-  $ printf "" > .hg/cache/hidden
-  $ hg log -r . -T '{node}' --debug
-  corrupted hidden cache
-  8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
-  $ hg log -r . -T '{node}' --debug
-  8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
-
-#if unix-permissions
-Check that wrong hidden cache permission does not crash
-
-  $ chmod 000 .hg/cache/hidden
-  $ hg log -r . -T '{node}' --debug
-  cannot read hidden cache
-  error writing hidden changesets cache
-  8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
-#endif
-
 Test cache consistency for the visible filter
 1) We want to make sure that the cached filtered revs are invalidated when
 bookmarks change