# HG changeset patch # User Pierre-Yves David # Date 2016-08-09 15:00:38 # Node ID d4e026341e1632e43eac0eb06f85ca599ee172c5 # Parent 82e8c86cdd6d068475c092c9b215b67433620c38 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 --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -987,7 +987,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. @@ -997,7 +997,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 --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -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 --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -1536,8 +1536,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 --git a/tests/test-bundle2-multiple-changegroups.t b/tests/test-bundle2-multiple-changegroups.t --- a/tests/test-bundle2-multiple-changegroups.t +++ b/tests/test-bundle2-multiple-changegroups.t @@ -3,7 +3,7 @@ Create an extension to test bundle2 with $ cat > bundle2.py < """ > """ - > 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 --git a/tests/test-bundle2-remote-changegroup.t b/tests/test-bundle2-remote-changegroup.t --- a/tests/test-bundle2-remote-changegroup.t +++ b/tests/test-bundle2-remote-changegroup.t @@ -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')