Patchwork [5,of,8] changegroup: introduce "raw" versions of some commands

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

Comments

Sune Foldager - Oct. 17, 2014, 1:14 p.m.
# HG changeset patch
# User Sune Foldager <cryo@cyanite.org>
# Date 1413549662 -7200
#      Fri Oct 17 14:41:02 2014 +0200
# Node ID 6edb4ba898143d38b35f04c475a9f2073688805d
# Parent  a95c01e22321a83e2a2271aeab4b53434b81edd9
changegroup: introduce "raw" versions of some commands

The commands getchangegroup, getlocalchangegroup and getsubset now each
have a version ending in -raw. The raw versions return the chunk generator
from the changegroup packer directly, without wrapping it in a chunkbuffer
and unpacker. This avoids extra chunkbuffers in the bundle2 code path.

Also, the raw versions can be extended to support alternative packers
in the future, to be used from bundle2.

Patch

diff -r a95c01e22321 -r 6edb4ba89814 mercurial/changegroup.py
--- a/mercurial/changegroup.py	Fri Oct 17 14:40:54 2014 +0200
+++ b/mercurial/changegroup.py	Fri Oct 17 14:41:02 2014 +0200
@@ -443,7 +443,7 @@ 
         for node in nodes:
             repo.ui.debug("%s\n" % hex(node))
 
-def getsubset(repo, outgoing, bundler, source, fastpath=False):
+def getsubsetraw(repo, outgoing, bundler, source, fastpath=False):
     repo = repo.unfiltered()
     commonrevs = outgoing.common
     csets = outgoing.missing
@@ -457,7 +457,10 @@ 
 
     repo.hook('preoutgoing', throw=True, source=source)
     _changegroupinfo(repo, csets, source)
-    gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source)
+    return bundler.generate(commonrevs, csets, fastpathlinkrev, source)
+
+def getsubset(repo, outgoing, bundler, source, fastpath=False):
+    gengroup = getsubsetraw(repo, outgoing, bundler, source, fastpath)
     return cg1unpacker(util.chunkbuffer(gengroup), 'UN')
 
 def changegroupsubset(repo, roots, heads, source):
@@ -485,6 +488,16 @@ 
     bundler = cg1packer(repo)
     return getsubset(repo, outgoing, bundler, source)
 
+def getlocalchangegroupraw(repo, source, outgoing, bundlecaps=None):
+    """Like getbundle, but taking a discovery.outgoing as an argument.
+
+    This is only implemented for local repos and reuses potentially
+    precomputed sets in outgoing. Returns a raw changegroup generator."""
+    if not outgoing.missing:
+        return None
+    bundler = cg1packer(repo, bundlecaps)
+    return getsubsetraw(repo, outgoing, bundler, source)
+
 def getlocalchangegroup(repo, source, outgoing, bundlecaps=None):
     """Like getbundle, but taking a discovery.outgoing as an argument.
 
@@ -514,6 +527,18 @@ 
         heads = cl.heads()
     return discovery.outgoing(cl, common, heads)
 
+def getchangegroupraw(repo, source, heads=None, common=None, bundlecaps=None):
+    """Like changegroupsubset, but returns the set difference between the
+    ancestors of heads and the ancestors common.
+
+    If heads is None, use the local heads. If common is None, use [nullid].
+
+    The nodes in common might not all be known locally due to the way the
+    current discovery protocol works. Returns a raw changegroup generator.
+    """
+    outgoing = _computeoutgoing(repo, heads, common)
+    return getlocalchangegroupraw(repo, source, outgoing, bundlecaps=bundlecaps)
+
 def getchangegroup(repo, source, heads=None, common=None, bundlecaps=None):
     """Like changegroupsubset, but returns the set difference between the
     ancestors of heads and the ancestors common.
diff -r a95c01e22321 -r 6edb4ba89814 mercurial/exchange.py
--- a/mercurial/exchange.py	Fri Oct 17 14:40:54 2014 +0200
+++ b/mercurial/exchange.py	Fri Oct 17 14:41:02 2014 +0200
@@ -441,8 +441,9 @@ 
                                      pushop.outgoing)
     if not pushop.force:
         bundler.newpart('B2X:CHECK:HEADS', data=iter(pushop.remoteheads))
-    cg = changegroup.getlocalchangegroup(pushop.repo, 'push', pushop.outgoing)
-    cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg.getchunks())
+    cg = changegroup.getlocalchangegroupraw(pushop.repo, 'push',
+                                            pushop.outgoing)
+    cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg)
     def handlereply(op):
         """extract addchangroup returns from server reply"""
         cgreplies = op.records.getreplies(cgpart.id)
@@ -1171,11 +1172,11 @@ 
     cg = None
     if kwargs.get('cg', True):
         # build changegroup bundle here.
-        cg = changegroup.getchangegroup(repo, source, heads=heads,
-                                        common=common, bundlecaps=bundlecaps)
+        cg = changegroup.getchangegroupraw(repo, source, heads=heads,
+                                           common=common, bundlecaps=bundlecaps)
 
     if cg:
-        bundler.newpart('b2x:changegroup', data=cg.getchunks())
+        bundler.newpart('b2x:changegroup', data=cg)
 
 @getbundle2partsgenerator('listkeys')
 def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,