repoview: move function for computing filtered hash
authorGregory Szorc <gregory.szorc@gmail.com>
Wed, 01 Apr 2015 18:43:29 -0700
changeset 24723 467a33142425
parent 24722 02a5618e2fbf
child 24724 95eb067b2b5e
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.
mercurial/branchmap.py
mercurial/scmutil.py
--- a/mercurial/branchmap.py	Tue Apr 14 12:54:16 2015 -0400
+++ b/mercurial/branchmap.py	Wed Apr 01 18:43:29 2015 -0700
@@ -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 @@
         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 @@
         - 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 @@
                 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',
--- a/mercurial/scmutil.py	Tue Apr 14 12:54:16 2015 -0400
+++ b/mercurial/scmutil.py	Wed Apr 01 18:43:29 2015 -0700
@@ -172,6 +172,30 @@
         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"""