[PATCH 3 of 4] changegroup: new bundler API

Benoit Boissinot bboissin at gmail.com
Sun May 1 10:27:04 CDT 2011


# HG changeset patch
# User Benoit Boissinot <benoit.boissinot at ens-lyon.org>
# Date 1304154208 -7200
# Node ID 9b91ea4c3d7c534d11a6730135328a26d20fc771
# Parent  03674fb75a2d274d180eb9fae1b066c60227f0a6
changegroup: new bundler API

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -6,7 +6,8 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import util
+from node import nullrev
+import mdiff, util
 import struct, os, bz2, zlib, tempfile
 
 _BUNDLE10_DELTA_HEADER = "20s20s20s20s"
@@ -212,16 +213,33 @@
     return unbundle10(fh, alg)
 
 class bundle10(object):
+    deltaheader = _BUNDLE10_DELTA_HEADER
     def __init__(self, lookup):
         self._lookup = lookup
     def close(self):
         return closechunk()
     def fileheader(self, fname):
         return chunkheader(len(fname)) + fname
-    def revchunk(self, revlog, node='', p1='', p2='', prefix='', data=''):
+    def revchunk(self, revlog, rev, prev):
+        node = revlog.node(rev)
+        p1, p2 = revlog.parentrevs(rev)
+        base = prev
+
+        prefix = ''
+        if base == nullrev:
+            delta = revlog.revision(node)
+            prefix = mdiff.trivialdiffheader(len(delta))
+        else:
+            delta = revlog.revdiff(base, rev)
         linknode = self._lookup(revlog, node)
-        meta = node + p1 + p2 + linknode + prefix
-        l = len(meta) + len(data)
+        p1n, p2n = revlog.parents(node)
+        basenode = revlog.node(base)
+        meta = self.builddeltaheader(node, p1n, p2n, basenode, linknode)
+        meta += prefix
+        l = len(meta) + len(delta)
         yield chunkheader(l)
         yield meta
-        yield data
+        yield delta
+    def builddeltaheader(self, node, p1n, p2n, basenode, linknode):
+        # do nothing with basenode, it is implicitly the previous one in HG10
+        return struct.pack(self.deltaheader, node, p1n, p2n, linknode)
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1086,17 +1086,8 @@
 
         # build deltas
         for r in xrange(len(revs) - 1):
-            a, b = revs[r], revs[r + 1]
-            nb = self.node(b)
-            p1, p2 = self.parents(nb)
-            prefix = ''
-
-            if a == nullrev:
-                d = self.revision(nb)
-                prefix = mdiff.trivialdiffheader(len(d))
-            else:
-                d = self.revdiff(a, b)
-            for c in bundler.revchunk(self, nb, p1, p2, prefix, d):
+            prev, curr = revs[r], revs[r + 1]
+            for c in bundler.revchunk(self, curr, prev):
                 yield c
 
         yield bundler.close()


More information about the Mercurial-devel mailing list