Patchwork [7,of,8] exchange: use getchangegroupchunks()

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 5, 2016, 3:17 a.m.
Message ID <4c9b71d4c61cf99cd754.1470367023@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16111/
State Accepted
Headers show

Comments

Gregory Szorc - Aug. 5, 2016, 3:17 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1470364829 25200
#      Thu Aug 04 19:40:29 2016 -0700
# Node ID 4c9b71d4c61cf99cd75469bff7d58bf0b2241bdd
# Parent  0270c4c4c1aef296d0405950a34bdef3aaa01f30
exchange: use getchangegroupchunks()

changegroup.getlocalchangegroupraw() is a one-liner that calls
getchangegroupchunks(). exchange.py is the only caller of this
function. Let's refactor exchange.py to use the new generic API.
Pierre-Yves David - Aug. 6, 2016, 12:48 a.m.
On 08/05/2016 05:17 AM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1470364829 25200
> #      Thu Aug 04 19:40:29 2016 -0700
> # Node ID 4c9b71d4c61cf99cd75469bff7d58bf0b2241bdd
> # Parent  0270c4c4c1aef296d0405950a34bdef3aaa01f30
> exchange: use getchangegroupchunks()
>
> changegroup.getlocalchangegroupraw() is a one-liner that calls
> getchangegroupchunks(). exchange.py is the only caller of this
> function. Let's refactor exchange.py to use the new generic API.

small nits, the rename of all cg to chunks here makes this patch much 
more complicated to review than it should be. I would suggest doing the 
two things appart.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -713,20 +713,22 @@  def _pushb2ctx(pushop, bundler):
     cgversions = b2caps.get('changegroup')
     if cgversions:  # 3.1 and 3.2 ship with an empty value
         cgversions = [v for v in cgversions
                       if v in changegroup.supportedoutgoingversions(
                           pushop.repo)]
         if not cgversions:
             raise ValueError(_('no common changegroup version'))
         version = max(cgversions)
-    cg = changegroup.getlocalchangegroupraw(pushop.repo, 'push',
-                                            pushop.outgoing,
-                                            version=version)
-    cgpart = bundler.newpart('changegroup', data=cg)
+
+    chunks = changegroup.getchangegroupchunks(pushop.repo,
+                                              pushop.outgoing,
+                                              version,
+                                              'push')[1]
+    cgpart = bundler.newpart('changegroup', data=chunks)
     if cgversions:
         cgpart.addparam('version', version)
     if 'treemanifest' in pushop.repo.requirements:
         cgpart.addparam('treemanifest', '1')
     def handlereply(op):
         """extract addchangegroup returns from server reply"""
         cgreplies = op.records.getreplies(cgpart.id)
         assert len(cgreplies['changegroup']) == 1
@@ -1568,24 +1570,23 @@  def _getbundlechangegrouppart(bundler, r
     cgversions = b2caps.get('changegroup')
     if cgversions:  # 3.1 and 3.2 ship with an empty value
         cgversions = [v for v in cgversions
                       if v in changegroup.supportedoutgoingversions(repo)]
         if not cgversions:
             raise ValueError(_('no common changegroup version'))
         version = max(cgversions)
     outgoing = discovery.outgoingheadsandcommon(repo, heads, common)
-    cg = changegroup.getlocalchangegroupraw(repo, source, outgoing,
-                                            bundlecaps=bundlecaps,
-                                            version=version)
-
-    if not cg:
+    chunks = changegroup.getchangegroupchunks(repo, outgoing,
+                                              version, source,
+                                              bundlecaps=bundlecaps)[1]
+    if not chunks:
         return
 
-    part = bundler.newpart('changegroup', data=cg)
+    part = bundler.newpart('changegroup', data=chunks)
     if cgversions:
         part.addparam('version', version)
     part.addparam('nbchanges', str(len(outgoing.missing)), mandatory=False)
     if 'treemanifest' in repo.requirements:
         part.addparam('treemanifest', '1')
 
 @getbundle2partsgenerator('listkeys')
 def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,