changegroup: replace getsubset with makechangegroup
authorDurham Goode <durham@fb.com>
Sun, 10 Sep 2017 18:39:02 -0700
changeset 34111 f85dfde1731a
parent 34110 7471193be725
child 34112 f7d41b85bbf6
changegroup: replace getsubset with makechangegroup The current changegroup APIs are a bit of a mess. Currently you can use getsubsetraw, getsubset, changegroupsubset, getlocalchangegroupraw, getchangegroup, and getlocalchangroup to produce changegroups. This patch is the beginning of a refactor to boil all of that away to just makechangegroup and makestream. The first step adds the new functions and replaces getsubset function with them. Differential Revision: https://phab.mercurial-scm.org/D664
mercurial/changegroup.py
mercurial/exchange.py
--- a/mercurial/changegroup.py	Wed Sep 06 16:17:04 2017 -0700
+++ b/mercurial/changegroup.py	Sun Sep 10 18:39:02 2017 -0700
@@ -912,6 +912,18 @@
         for node in nodes:
             repo.ui.debug("%s\n" % hex(node))
 
+def makestream(repo, outgoing, version, source, fastpath=False,
+               bundlecaps=None):
+    bundler = getbundler(version, repo, bundlecaps=bundlecaps)
+    return getsubsetraw(repo, outgoing, bundler, source, fastpath=fastpath)
+
+def makechangegroup(repo, outgoing, version, source, fastpath=False,
+                    bundlecaps=None):
+    cgstream = makestream(repo, outgoing, version, source,
+                          fastpath=fastpath, bundlecaps=bundlecaps)
+    return getunbundler(version, util.chunkbuffer(cgstream), None,
+                        {'clcount': len(outgoing.missing) })
+
 def getsubsetraw(repo, outgoing, bundler, source, fastpath=False):
     repo = repo.unfiltered()
     commonrevs = outgoing.common
@@ -928,11 +940,6 @@
     _changegroupinfo(repo, csets, source)
     return bundler.generate(commonrevs, csets, fastpathlinkrev, source)
 
-def getsubset(repo, outgoing, bundler, source, fastpath=False):
-    gengroup = getsubsetraw(repo, outgoing, bundler, source, fastpath)
-    return getunbundler(bundler.version, util.chunkbuffer(gengroup), None,
-                        {'clcount': len(outgoing.missing)})
-
 def changegroupsubset(repo, roots, heads, source, version='01'):
     """Compute a changegroup consisting of all the nodes that are
     descendants of any of the roots and ancestors of any of the heads.
@@ -947,8 +954,7 @@
     the changegroup a particular filenode or manifestnode belongs to.
     """
     outgoing = discovery.outgoing(repo, missingroots=roots, missingheads=heads)
-    bundler = getbundler(version, repo)
-    return getsubset(repo, outgoing, bundler, source)
+    return makechangegroup(repo, outgoing, version, source)
 
 def getlocalchangegroupraw(repo, source, outgoing, bundlecaps=None,
                            version='01'):
@@ -969,8 +975,8 @@
     precomputed sets in outgoing."""
     if not outgoing.missing:
         return None
-    bundler = getbundler(version, repo, bundlecaps)
-    return getsubset(repo, outgoing, bundler, source)
+    return makechangegroup(repo, outgoing, version, source,
+                           bundlecaps=bundlecaps)
 
 def getlocalchangegroup(repo, *args, **kwargs):
     repo.ui.deprecwarn('getlocalchangegroup is deprecated, use getchangegroup',
--- a/mercurial/exchange.py	Wed Sep 06 16:17:04 2017 -0700
+++ b/mercurial/exchange.py	Sun Sep 10 18:39:02 2017 -0700
@@ -963,12 +963,8 @@
                             or pushop.repo.changelog.filteredrevs):
         # push everything,
         # use the fast path, no race possible on push
-        bundler = changegroup.cg1packer(pushop.repo, bundlecaps)
-        cg = changegroup.getsubset(pushop.repo,
-                                   outgoing,
-                                   bundler,
-                                   'push',
-                                   fastpath=True)
+        cg = changegroup.makechangegroup(pushop.repo, outgoing, '01', 'push',
+                fastpath=True, bundlecaps=bundlecaps)
     else:
         cg = changegroup.getchangegroup(pushop.repo, 'push', outgoing,
                                         bundlecaps=bundlecaps)