# HG changeset patch # User Gregory Szorc # Date 2015-04-02 01:43:29 # Node ID 467a33142425c60580c27b78736e73ae3cbd8cfd # Parent 02a5618e2fbf29bca3b9045379a3666e441f2569 repoview: move function for computing filtered hash An upcoming patch will establish per-filter tags caches. We'll want to use the same cache validation logic as the branch cache. Prepare for that by moving the logic for computing a filtered view hash to somewhere central. diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -7,6 +7,7 @@ from node import bin, hex, nullid, nullrev import encoding +import scmutil import util import time from array import array @@ -136,27 +137,6 @@ class branchcache(dict): else: self._closednodes = closednodes - def _hashfiltered(self, repo): - """build hash of revision filtered in the current cache - - Tracking tipnode and tiprev is not enough to ensure validity of the - cache as they do not help to distinct cache that ignored various - revision bellow tiprev. - - To detect such difference, we build a cache of all ignored revisions. - """ - cl = repo.changelog - if not cl.filteredrevs: - return None - key = None - revs = sorted(r for r in cl.filteredrevs if r <= self.tiprev) - if revs: - s = util.sha1() - for rev in revs: - s.update('%s;' % rev) - key = s.digest() - return key - def validfor(self, repo): """Is the cache content valid regarding a repo @@ -164,7 +144,8 @@ class branchcache(dict): - True when cache is up to date or a subset of current repo.""" try: return ((self.tipnode == repo.changelog.node(self.tiprev)) - and (self.filteredhash == self._hashfiltered(repo))) + and (self.filteredhash == \ + scmutil.filteredhash(repo, self.tiprev))) except IndexError: return False @@ -283,7 +264,7 @@ class branchcache(dict): if tiprev > self.tiprev: self.tipnode = cl.node(tiprev) self.tiprev = tiprev - self.filteredhash = self._hashfiltered(repo) + self.filteredhash = scmutil.filteredhash(repo, self.tiprev) duration = time.time() - starttime repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n', diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -172,6 +172,30 @@ class casecollisionauditor(object): self._loweredfiles.add(fl) self._newfiles.add(f) +def filteredhash(repo, maxrev): + """build hash of filtered revisions in the current repoview. + + Multiple caches perform up-to-date validation by checking that the + tiprev and tipnode stored in the cache file match the current repository. + However, this is not sufficient for validating repoviews because the set + of revisions in the view may change without the repository tiprev and + tipnode changing. + + This function hashes all the revs filtered from the view and returns + that SHA-1 digest. + """ + cl = repo.changelog + if not cl.filteredrevs: + return None + key = None + revs = sorted(r for r in cl.filteredrevs if r <= maxrev) + if revs: + s = util.sha1() + for rev in revs: + s.update('%s;' % rev) + key = s.digest() + return key + class abstractvfs(object): """Abstract base class; cannot be instantiated"""