Patchwork [5,of,9,changegroup-apis] changegroup: add fromheadsandcommon() convenience function

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 1, 2016, 6:18 p.m.
Message ID <caf03d083a56111fc568.1470075502@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16019/
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 1469901727 25200
#      Sat Jul 30 11:02:07 2016 -0700
# Node ID caf03d083a56111fc568735bd83c99150ae3be7f
# Parent  a96f832a74148b5d9fdc3649254ca745c9f98c47
changegroup: add fromheadsandcommon() convenience function

Callers should not have to create an ``outgoing`` instance themselves.
We add a convenience API to construct a ``changegroupemitter`` from
a list of heads and common nodes.

A caller in exchange.py has been converted to the new function to
show that it works.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -1059,16 +1059,29 @@  class changegroupemitter(object):
         self._heads = heads
 
     @classmethod
     def fromoutgoing(cls, repo, outgoing):
         """Construct an instance from a ``discovery.outgoing`` instance."""
         return cls(repo, outgoing.common, outgoing.missing,
                    outgoing.missingheads)
 
+    @classmethod
+    def fromheadsandcommon(cls, repo, heads, common):
+        """Construct an instance from heads and common nodes.
+
+        ``heads`` is a list of binary nodes that are wanted by the
+        destination. ``common`` is a list of binary nodes that are
+        common between this repo and the destination. The missing
+        nodes between ``common`` and ``heads`` will be included in the
+        changegroup.
+        """
+        outgoing = computeoutgoing(repo, heads, common)
+        return changegroupemitter.fromoutgoing(repo, outgoing)
+
     @property
     def changesetcount(self):
         """The number of changesets in this changegroup."""
         return len(self._nodes)
 
     def emitchangegroupdata(self, version, source, bundlecaps=None,
                             fastpathlinkrev=False):
         """Emit raw changegroup data.
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1559,18 +1559,18 @@  def _getbundlechangegrouppart(bundler, r
     version = '01'
     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)
-    emitter = changegroup.changegroupemitter.fromoutgoing(repo, outgoing)
+    emitter = changegroup.changegroupemitter.fromheadsandcommon(repo, heads,
+                                                                common)
     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(emitter.changesetcount), mandatory=False)