[PATCH 4 of 4] imported patch minimal-delta

Pradeepkumar Gayam in3xes at gmail.com
Tue Jun 22 02:31:05 CDT 2010


# HG changeset patch
# User Pradeepkumar Gayam <in3xes at gmail.com>
# Date 1277183801 -19800
# Node ID 0c8bf10047f95e5c6b9b57284819835b8cbedf6d
# Parent  7060a4d066fb28d08eaec62a46bd45b96fbfe4be
imported patch minimal-delta

diff -r 7060a4d066fb -r 0c8bf10047f9 mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Jun 22 10:46:41 2010 +0530
+++ b/mercurial/revlog.py	Tue Jun 22 10:46:41 2010 +0530
@@ -1001,7 +1001,7 @@
         if self.base(rev) == rev:
             return nullrev
         elif self.flags(rev) & REVLOG_PARENTDELTA_FLAGS:
-            return self.parentrevs(rev)[0]
+            return self.base(rev)
         else:
             return rev-1
 
@@ -1134,25 +1134,35 @@
         prev = curr - 1
         base = self.base(prev)
         offset = self.end(prev)
-        flags = REVLOG_PARENTDELTA_FLAGS
+        if p1 != nullrev and p2 != nullrev:
+            p1, p2 = self.rev(p1), self.rev(p2)
+        flags = 0
 
-        if curr:
-            if not d:
-                ptext = self.revision(p1)
+        def candidates(parents):
+            fulldata = compress(text)
+            fulllen = len(fulldata[1]) + len(fulldata[0])
+            yield (fulllen, curr, fulldata)
+
+            for p in parents:
+                ptext = self.revision(self.node(p))
                 d = mdiff.textdiff(ptext, text)
-            data = compress(d)
-            l = len(data[1]) + len(data[0])
-            dist = l + offset - self.start(base)
+                data = compress(d)
+                l = len(data[1]) + len(data[0])
+                base, chain = self.deltachain(p)
+                dist = l + offset - self.start(base)
+                if dist > len(text)*3:
+                    yield l, p, data
 
-        # full versions are inserted when the needed deltas
-        # become comparable to the uncompressed text
-        if not curr or dist > len(text) * 2:
-            data = compress(text)
-            l = len(data[1]) + len(data[0])
-            base = curr
+        l, p, data = min(candidates(p for p in (prev, p1, p2) if p != nullrev))
+        if p == prev:
+            base = self.base(prev)
+        else:
+            base = p
+            if p < prev:
+                flags = 1
 
         e = (offset_type(offset, flags), l, len(text),
-             base, link, self.rev(p1), self.rev(p2), node)
+             base, link, p1, p2, node)
         self.index.insert(-1, e)
         self.nodemap[node] = curr
 


More information about the Mercurial-devel mailing list