changeset 14143:da635d3c5620

changegroup: new bundler API
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sat, 30 Apr 2011 11:03:28 +0200
parents cb91ea6af733
children 3c3c53d8343a
files mercurial/changegroup.py mercurial/revlog.py
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Sat Apr 30 10:41:06 2011 +0200
+++ b/mercurial/changegroup.py	Sat Apr 30 11:03:28 2011 +0200
@@ -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)
--- a/mercurial/revlog.py	Sat Apr 30 10:41:06 2011 +0200
+++ b/mercurial/revlog.py	Sat Apr 30 11:03:28 2011 +0200
@@ -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()