[PATCH 4 of 5] getchangegroup: take an 'outgoing' object as argument (API)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Aug 11 16:06:54 EDT 2016


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1470754838 -7200
#      Tue Aug 09 17:00:38 2016 +0200
# Node ID 0a35b949b92ac83e66ddaa706deb8c0f228a045b
# Parent  8c4fcb1244bdf79caadadc73fc1e489a160a07ec
# EXP-Topic outgoing
getchangegroup: take an 'outgoing' object as argument (API)

There is various version of this function that differ mostly by the way they
define the bundled set. The flexibility is now available in the outgoing object
itself so we move the complexity into the caller themself. This will allow use
to remove a good share of the similar function to obtains a changegroup in the
'changegroup.py' module.

An important side effect is that we stop calling 'computeoutgoing' in
'getchangegroup'. This is fine as code that needs such argument processing
is actually going through the 'exchange' module which already all this function
itself.

diff -r 8c4fcb1244bd -r 0a35b949b92a mercurial/changegroup.py
--- a/mercurial/changegroup.py	Tue Aug 09 22:31:38 2016 +0200
+++ b/mercurial/changegroup.py	Tue Aug 09 17:00:38 2016 +0200
@@ -988,7 +988,7 @@ def computeoutgoing(repo, heads, common)
         heads = cl.heads()
     return discovery.outgoing(repo, common, heads)
 
-def getchangegroup(repo, source, heads=None, common=None, bundlecaps=None,
+def getchangegroup(repo, source, outgoing, bundlecaps=None,
                    version='01'):
     """Like changegroupsubset, but returns the set difference between the
     ancestors of heads and the ancestors common.
@@ -998,7 +998,6 @@ def getchangegroup(repo, source, heads=N
     The nodes in common might not all be known locally due to the way the
     current discovery protocol works.
     """
-    outgoing = computeoutgoing(repo, heads, common)
     return getlocalchangegroup(repo, source, outgoing, bundlecaps=bundlecaps,
                                version=version)
 
diff -r 8c4fcb1244bd -r 0a35b949b92a mercurial/commands.py
--- a/mercurial/commands.py	Tue Aug 09 22:31:38 2016 +0200
+++ b/mercurial/commands.py	Tue Aug 09 17:00:38 2016 +0200
@@ -1412,9 +1412,10 @@ def bundle(ui, repo, fname, dest=None, *
                                "a destination"))
         common = [repo.lookup(rev) for rev in base]
         heads = revs and map(repo.lookup, revs) or revs
-        cg = changegroup.getchangegroup(repo, 'bundle', heads=heads,
-                                         common=common, bundlecaps=bundlecaps,
-                                         version=cgversion)
+        outgoing = discovery.outgoing(repo, common, heads)
+        cg = changegroup.getchangegroup(repo, 'bundle', outgoing,
+                                        bundlecaps=bundlecaps,
+                                        version=cgversion)
         outgoing = None
     else:
         dest = ui.expandpath(dest or 'default-push', dest or 'default')
diff -r 8c4fcb1244bd -r 0a35b949b92a mercurial/exchange.py
--- a/mercurial/exchange.py	Tue Aug 09 22:31:38 2016 +0200
+++ b/mercurial/exchange.py	Tue Aug 09 17:00:38 2016 +0200
@@ -1535,8 +1535,9 @@ def getbundle(repo, source, heads=None, 
         if kwargs:
             raise ValueError(_('unsupported getbundle arguments: %s')
                              % ', '.join(sorted(kwargs.keys())))
-        return changegroup.getchangegroup(repo, source, heads=heads,
-                                          common=common, bundlecaps=bundlecaps)
+        outgoing = changegroup.computeoutgoing(repo, heads, common)
+        return changegroup.getchangegroup(repo, source, outgoing,
+                                          bundlecaps=bundlecaps)
 
     # bundle20 case
     b2caps = {}
diff -r 8c4fcb1244bd -r 0a35b949b92a tests/test-bundle2-multiple-changegroups.t
--- a/tests/test-bundle2-multiple-changegroups.t	Tue Aug 09 22:31:38 2016 +0200
+++ b/tests/test-bundle2-multiple-changegroups.t	Tue Aug 09 17:00:38 2016 +0200
@@ -3,7 +3,7 @@ Create an extension to test bundle2 with
   $ cat > bundle2.py <<EOF
   > """
   > """
-  > from mercurial import changegroup, exchange
+  > from mercurial import changegroup, discovery, exchange
   > 
   > def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
   >                               b2caps=None, heads=None, common=None,
@@ -12,13 +12,14 @@ Create an extension to test bundle2 with
   >     # changegroup part we are being requested. Use the parent of each head
   >     # in 'heads' as intermediate heads for the first changegroup.
   >     intermediates = [repo[r].p1().node() for r in heads]
-  >     cg = changegroup.getchangegroup(repo, source, heads=intermediates,
-  >                                      common=common, bundlecaps=bundlecaps)
+  >     outgoing = discovery.outgoing(repo, common, intermediates)
+  >     cg = changegroup.getchangegroup(repo, source, outgoing,
+  >                                     bundlecaps=bundlecaps)
   >     bundler.newpart('output', data='changegroup1')
   >     bundler.newpart('changegroup', data=cg.getchunks())
-  >     cg = changegroup.getchangegroup(repo, source, heads=heads,
-  >                                      common=common + intermediates,
-  >                                      bundlecaps=bundlecaps)
+  >     outgoing = discovery.outgoing(repo, common + intermediates, heads)
+  >     cg = changegroup.getchangegroup(repo, source, outgoing,
+  >                                     bundlecaps=bundlecaps)
   >     bundler.newpart('output', data='changegroup2')
   >     bundler.newpart('changegroup', data=cg.getchunks())
   > 
diff -r 8c4fcb1244bd -r 0a35b949b92a tests/test-bundle2-remote-changegroup.t
--- a/tests/test-bundle2-remote-changegroup.t	Tue Aug 09 22:31:38 2016 +0200
+++ b/tests/test-bundle2-remote-changegroup.t	Tue Aug 09 17:00:38 2016 +0200
@@ -8,7 +8,7 @@ Create an extension to test bundle2 remo
   > Current bundle2 implementation doesn't provide a way to generate those
   > parts, so they must be created by extensions.
   > """
-  > from mercurial import bundle2, changegroup, exchange, util
+  > from mercurial import bundle2, changegroup, discovery, exchange, util
   > 
   > def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
   >                               b2caps=None, heads=None, common=None,
@@ -22,7 +22,7 @@ Create an extension to test bundle2 remo
   >     part to add:
   >       - changegroup common_revset heads_revset
   >           Creates a changegroup part based, using common_revset and
-  >           heads_revset for changegroup.getchangegroup.
+  >           heads_revset for outgoing
   >       - remote-changegroup url file
   >           Creates a remote-changegroup part for a bundle at the given
   >           url. Size and digest, as required by the client, are computed
@@ -63,8 +63,8 @@ Create an extension to test bundle2 remo
   >             _common, heads = args.split()
   >             common.extend(repo.lookup(r) for r in repo.revs(_common))
   >             heads = [repo.lookup(r) for r in repo.revs(heads)]
-  >             cg = changegroup.getchangegroup(repo, 'changegroup',
-  >                 heads=heads, common=common)
+  >             outgoing = discovery.outgoing(repo, common, heads)
+  >             cg = changegroup.getchangegroup(repo, 'changegroup', outgoing)
   >             newpart('changegroup', cg.getchunks())
   >         else:
   >             raise Exception('unknown verb')


More information about the Mercurial-devel mailing list