Patchwork [6,of,8] changegroup: introduce cg2packer/unpacker

login
register
mail settings
Submitter Sune Foldager
Date Oct. 17, 2014, 1:14 p.m.
Message ID <958fbc8c90b8d2e5eab4.1413551697@Cuivienen.local>
Download mbox | patch
Permalink /patch/6365/
State Superseded
Headers show

Comments

Sune Foldager - Oct. 17, 2014, 1:14 p.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1413549671 -7200
#      Fri Oct 17 14:41:11 2014 +0200
# Node ID 958fbc8c90b8d2e5eab44909e99705e615375b78
# Parent  6edb4ba898143d38b35f04c475a9f2073688805d
changegroup: introduce cg2packer/unpacker

cg2 supports generaldelta in changegroups, to be used in bundle2.
Since generaldelta is handled directly in cg2, reordering is switched
off by default.

Patch

diff -r 6edb4ba89814 -r 958fbc8c90b8 mercurial/changegroup.py
--- a/mercurial/changegroup.py	Fri Oct 17 14:41:02 2014 +0200
+++ b/mercurial/changegroup.py	Fri Oct 17 14:41:11 2014 +0200
@@ -13,6 +13,7 @@ 
 import discovery, error, phases, branchmap
 
 _CHANGEGROUPV1_DELTA_HEADER = "20s20s20s20s"
+_CHANGEGROUPV2_DELTA_HEADER = "20s20s20s20s20s"
 
 def readexactly(stream, n):
     '''read n bytes from stream.read and abort if less was available'''
@@ -215,6 +216,15 @@ 
                     pos = next
             yield closechunk()
 
+class cg2unpacker(cg1unpacker):
+    deltaheader = _CHANGEGROUPV2_DELTA_HEADER
+    deltaheadersize = struct.calcsize(deltaheader)
+
+    def _deltaheader(self, headertuple, prevnode):
+        node, p1, p2, deltabase, cs = headertuple
+        return node, p1, p2, deltabase, cs
+
+
 class headerlessfixup(object):
     def __init__(self, fh, h):
         self._h = h
@@ -410,10 +420,13 @@ 
                                         reorder=reorder):
                     yield chunk
 
+    def deltaparent(self, revlog, rev, p1, p2, prev):
+        return prev
+
     def revchunk(self, revlog, rev, prev, linknode):
         node = revlog.node(rev)
         p1, p2 = revlog.parentrevs(rev)
-        base = prev
+        base = self.deltaparent(revlog, rev, p1, p2, prev)
 
         prefix = ''
         if base == nullrev:
@@ -433,7 +446,29 @@ 
         # do nothing with basenode, it is implicitly the previous one in HG10
         return struct.pack(self.deltaheader, node, p1n, p2n, linknode)
 
-packermap = {'1': (cg1packer, cg1unpacker)}
+class cg2packer(cg1packer):
+
+    deltaheader = _CHANGEGROUPV2_DELTA_HEADER
+
+    def group(self, nodelist, revlog, lookup, units=None, reorder=None):
+        if (revlog._generaldelta and reorder is not True):
+            reorder = False
+        return cg1packer.group(self, nodelist, revlog, lookup,
+                               units=units, reorder=reorder)
+
+    def deltaparent(self, revlog, rev, p1, p2, prev):
+        dp = revlog.deltaparent(rev)
+        # avoid storing full revisions; pick prev in those cases
+        # also pick prev when we can't be sure remote has dp
+        if dp == nullrev or (dp != p1 and dp != p2 and dp != prev):
+            return prev
+        return dp
+
+    def builddeltaheader(self, node, p1n, p2n, basenode, linknode):
+        return struct.pack(self.deltaheader, node, p1n, p2n, basenode, linknode)
+
+packermap = {'1': (cg1packer, cg1unpacker),
+             '2': (cg2packer, cg2unpacker)}
 
 def _changegroupinfo(repo, nodes, source):
     if repo.ui.verbose or source == 'bundle':