[PATCH 02 of 15] revlog: deltachain() returns the chain of revisions to construct a given revision

Pradeepkumar Gayam in3xes at gmail.com
Mon Jul 12 05:49:44 CDT 2010


# HG changeset patch
# User Pradeepkumar Gayam <in3xes at gmail.com>
# Date 1278874604 -19800
# Branch stable
# Node ID 15579a3a578521f9bf3e3ad9db0e462c1ffba9f2
# Parent  3dce03cd1a40cfc48a4de05c091fc8da277aa6c4
revlog: deltachain() returns the chain of revisions to construct a given revision

diff -r 3dce03cd1a40 -r 15579a3a5785 mercurial/revlog.py
--- a/mercurial/revlog.py	Mon Jul 12 00:16:19 2010 +0530
+++ b/mercurial/revlog.py	Mon Jul 12 00:26:44 2010 +0530
@@ -997,6 +997,15 @@
     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) & REVLOG_PARENTDELTA_FLAGS:
+            return self.parentrevs(rev)[0]
+        else:
+            return rev-1
+
     def revdiff(self, rev1, rev2):
         """return or calculate a delta between two revisions"""
         if rev1 + 1 == rev2 and self.base(rev1) == self.base(rev2):
@@ -1008,6 +1017,15 @@
     def flags(self, rev):
         return gettype(self.index[rev][0])
 
+    def deltachain(self, rev):
+        '''return chain of revisions to construct a given revision'''
+        chain = []
+        while self.base(rev) != rev:
+            chain.append(rev)
+            rev = self.deltaparent(rev)
+        chain.reverse()
+        return rev, chain
+
     def revision(self, node):
         """return an uncompressed revision of a given node"""
         if node == nullid:


More information about the Mercurial-devel mailing list