Patchwork [3,of,9,changegroup-apis] exchange: use changegroupemitter

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 1, 2016, 6:18 p.m.
Message ID <3504fd307dbcb6e36709.1470075500@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16017/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Gregory Szorc - Aug. 1, 2016, 6:18 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1469901065 25200
#      Sat Jul 30 10:51:05 2016 -0700
# Node ID 3504fd307dbcb6e367091081e638db3d106825c9
# Parent  c454ae28863fefa2a34c331901a139b627279b7b
exchange: use changegroupemitter

We now have a higher-level API for obtaining changegroup data. Start
using it.

This patch demonstrates how the state on the emitter instance can
later be used. The benefits are marginal since we already have an
outgoing instance in _getbundlechangegrouppart(). However, this
will be improved in future patches.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -705,19 +705,19 @@  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)
+    emitter = changegroup.changegroupemitter.fromoutgoing(pushop.repo,
+                                                          pushop.outgoing)
+    cg = emitter.emitchangegroupdata(version, 'push')
     cgpart = bundler.newpart('changegroup', data=cg)
     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)
@@ -1560,27 +1560,25 @@  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 = changegroup.computeoutgoing(repo, heads, common)
-    cg = changegroup.getlocalchangegroupraw(repo, source, outgoing,
-                                            bundlecaps=bundlecaps,
-                                            version=version)
-
+    emitter = changegroup.changegroupemitter.fromoutgoing(repo, outgoing)
+    cg = emitter.emitchangegroupdata(version, source, bundlecaps=bundlecaps)
     if not cg:
         return
 
     part = bundler.newpart('changegroup', data=cg)
     if cgversions:
         part.addparam('version', version)
-    part.addparam('nbchanges', str(len(outgoing.missing)), mandatory=False)
+    part.addparam('nbchanges', str(emitter.changesetcount), mandatory=False)
     if 'treemanifest' in repo.requirements:
         part.addparam('treemanifest', '1')
 
 @getbundle2partsgenerator('listkeys')
 def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,
                             b2caps=None, **kwargs):
     """add parts containing listkeys namespaces to the requested bundle"""
     listkeys = kwargs.get('listkeys', ())