changeset 11929:1839a7518b0d

revlog: deltachain() returns chain of revs need to construct a revision
author Pradeepkumar Gayam <in3xes@gmail.com>
date Tue, 10 Aug 2010 22:26:08 +0530
parents b69899dbad40
children 12547cedc264
files mercurial/revlog.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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):