diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
index 82e8c86cdd6d068475c092c9b215b67433620c38_bWVyY3VyaWFsL2NoYW5nZWdyb3VwLnB5..d4e026341e1632e43eac0eb06f85ca599ee172c5_bWVyY3VyaWFsL2NoYW5nZWdyb3VwLnB5 100644
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -987,7 +987,7 @@
         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.
@@ -997,7 +997,6 @@
     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 --git a/mercurial/commands.py b/mercurial/commands.py
index 82e8c86cdd6d068475c092c9b215b67433620c38_bWVyY3VyaWFsL2NvbW1hbmRzLnB5..d4e026341e1632e43eac0eb06f85ca599ee172c5_bWVyY3VyaWFsL2NvbW1hbmRzLnB5 100644
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1412,9 +1412,10 @@
                                "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 --git a/mercurial/exchange.py b/mercurial/exchange.py
index 82e8c86cdd6d068475c092c9b215b67433620c38_bWVyY3VyaWFsL2V4Y2hhbmdlLnB5..d4e026341e1632e43eac0eb06f85ca599ee172c5_bWVyY3VyaWFsL2V4Y2hhbmdlLnB5 100644
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1536,8 +1536,9 @@
         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 --git a/tests/test-bundle2-multiple-changegroups.t b/tests/test-bundle2-multiple-changegroups.t
index 82e8c86cdd6d068475c092c9b215b67433620c38_dGVzdHMvdGVzdC1idW5kbGUyLW11bHRpcGxlLWNoYW5nZWdyb3Vwcy50..d4e026341e1632e43eac0eb06f85ca599ee172c5_dGVzdHMvdGVzdC1idW5kbGUyLW11bHRpcGxlLWNoYW5nZWdyb3Vwcy50 100644
--- a/tests/test-bundle2-multiple-changegroups.t
+++ b/tests/test-bundle2-multiple-changegroups.t
@@ -3,7 +3,7 @@
   $ 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,7 +12,8 @@
   >     # 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())
@@ -17,8 +18,8 @@
   >     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 --git a/tests/test-bundle2-remote-changegroup.t b/tests/test-bundle2-remote-changegroup.t
index 82e8c86cdd6d068475c092c9b215b67433620c38_dGVzdHMvdGVzdC1idW5kbGUyLXJlbW90ZS1jaGFuZ2Vncm91cC50..d4e026341e1632e43eac0eb06f85ca599ee172c5_dGVzdHMvdGVzdC1idW5kbGUyLXJlbW90ZS1jaGFuZ2Vncm91cC50 100644
--- a/tests/test-bundle2-remote-changegroup.t
+++ b/tests/test-bundle2-remote-changegroup.t
@@ -8,7 +8,7 @@
   > 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 @@
   >     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 @@
   >             _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')