changeset 17677:5c89e7fa5bc2

clfilter: introduce `filteredrevs` attribute on changelog This changeset allows changelog object to be "filtered". You can assign a set of revision numbers to the `changelog.filteredrevs` attributes. The changelog will then pretends these revision does not exists in this repo. A few methods need to be altered to achieve this behavior: - tip - __iter_ - irevs - hasnode - headrevs For consistency and to help debugging, the following methods are altered too. Tests tend to show it's not necessary to alter them but have them raise proper exception helps to detect bad acces to filtered revisions. - rev - node - linkrev - parentrevs - flags The following methods would also need alteration for consistency purpose but this is non-trivial and not done yet. - nodemap - strip The C version of headrevs is not run if there is any revision to filter. It'll need a proper rewrite later to restore performance.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 20 Sep 2012 19:02:47 +0200
parents f87683a1b02a
children 60229b466e5a
files mercurial/changelog.py
diffstat 1 files changed, 76 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changelog.py	Mon Sep 03 14:29:05 2012 +0200
+++ b/mercurial/changelog.py	Thu Sep 20 19:02:47 2012 +0200
@@ -120,6 +120,82 @@
         self._realopener = opener
         self._delayed = False
         self._divert = False
+        self.filteredrevs = ()
+
+    def tip(self):
+        """filtered version of revlog.tip"""
+        for i in xrange(len(self) -1, -2, -1):
+            if i not in self.filteredrevs:
+                return self.node(i)
+
+    def __iter__(self):
+        """filtered version of revlog.__iter__"""
+        for i in xrange(len(self)):
+            if i not in self.filteredrevs:
+                yield i
+
+    def revs(self, start=0, stop=None):
+        """filtered version of revlog.revs"""
+        for i in super(changelog, self).revs(start, stop):
+            if i not in self.filteredrevs:
+                yield i
+
+    @util.propertycache
+    def nodemap(self):
+        # XXX need filtering too
+        self.rev(self.node(0))
+        return self._nodecache
+
+    def hasnode(self, node):
+        """filtered version of revlog.hasnode"""
+        try:
+            i = self.rev(node)
+            return i not in self.filteredrevs
+        except KeyError:
+            return False
+
+    def headrevs(self):
+        if self.filteredrevs:
+            # XXX we should fix and use the C version
+            return self._headrevs()
+        return super(changelog, self).headrevs()
+
+    def strip(self, *args, **kwargs):
+        # XXX make something better than assert
+        # We can't expect proper strip behavior if we are filtered.
+        assert not self.filteredrevs
+        super(changelog, self).strip(*args, **kwargs)
+
+    def rev(self, node):
+        """filtered version of revlog.rev"""
+        r = super(changelog, self).rev(node)
+        if r in self.filteredrevs:
+            raise error.LookupError(node, self.indexfile, _('no node'))
+        return r
+
+    def node(self, rev):
+        """filtered version of revlog.node"""
+        if rev in self.filteredrevs:
+            raise IndexError(rev)
+        return super(changelog, self).node(rev)
+
+    def linkrev(self, rev):
+        """filtered version of revlog.linkrev"""
+        if rev in self.filteredrevs:
+            raise IndexError(rev)
+        return super(changelog, self).linkrev(rev)
+
+    def parentrevs(self, rev):
+        """filtered version of revlog.parentrevs"""
+        if rev in self.filteredrevs:
+            raise IndexError(rev)
+        return super(changelog, self).parentrevs(rev)
+
+    def flags(self, rev):
+        """filtered version of revlog.flags"""
+        if rev in self.filteredrevs:
+            raise IndexError(rev)
+        return super(changelog, self).flags(rev)
 
     def delayupdate(self):
         "delay visibility of index updates to other readers"