revlog: deltachain() returns chain of revs need to construct a revision
authorPradeepkumar Gayam <in3xes@gmail.com>
Tue, 10 Aug 2010 22:26:08 +0530
changeset 11929 1839a7518b0d
parent 11928 b69899dbad40
child 11930 12547cedc264
revlog: deltachain() returns chain of revs need to construct a revision
mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Aug 10 22:25:08 2010 +0530
+++ b/mercurial/revlog.py	Tue Aug 10 22:26:08 2010 +0530
@@ -1016,6 +1016,28 @@
     def _chunkclear(self):
         self._chunkcache = (0, '')
 
+    def deltaparent(self, rev):
+        """return previous revision or parentrev according to flags"""
+        if self.base(rev) == rev:
+            return nullrev
+        elif self.flags(rev) & REVIDX_PARENTDELTA:
+            return self.parentrevs(rev)[0]
+        else:
+            return rev - 1
+
+
+    def deltachain(self, rev, cache):
+        """return chain of revisions to construct a given revision"""
+        chain = []
+        check = False
+        while self.base(rev) != rev and rev != cache:
+            chain.append(rev)
+            rev = self.deltaparent(rev)
+        chain.reverse()
+        if rev == cache:
+            check = True
+        return check, rev, chain
+
     def revdiff(self, rev1, rev2):
         """return or calculate a delta between two revisions"""
         if rev1 + 1 == rev2 and self.base(rev1) == self.base(rev2):