diff mercurial/scmutil.py @ 24723:467a33142425

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 01 Apr 2015 18:43:29 -0700
parents 0d28b0df77ea
children ee751d47cf2c
line wrap: on
line diff
--- 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"""