bundle2: return a stream from exchange.getbundle
For friendliness with the wire protocol implementation, the `exchange.getbundle` now
returns a binary stream when asked for a bundle2. We detect a bundle2 request and
upgrade the binary stream to an unbundler object.
In the future the unbundler may gain feature to look like a binary stream, but
we are not quite there yet.
--- a/mercurial/exchange.py Tue Apr 15 13:57:15 2014 -0400
+++ b/mercurial/exchange.py Tue Apr 15 11:27:55 2014 -0400
@@ -659,7 +659,7 @@
bundler = bundle2.bundle20(repo.ui)
part = bundle2.bundlepart('changegroup', data=cg.getchunks())
bundler.addpart(part)
- return bundle2.unbundle20(repo.ui, util.chunkbuffer(bundler.getchunks()))
+ return util.chunkbuffer(bundler.getchunks())
class PushRaced(RuntimeError):
"""An exception raised during unbundling that indicate a push race"""
--- a/mercurial/localrepo.py Tue Apr 15 13:57:15 2014 -0400
+++ b/mercurial/localrepo.py Tue Apr 15 11:27:55 2014 -0400
@@ -9,7 +9,7 @@
import peer, changegroup, subrepo, pushkey, obsolete, repoview
import changelog, dirstate, filelog, manifest, context, bookmarks, phases
import lock as lockmod
-import transaction, store, encoding, exchange
+import transaction, store, encoding, exchange, bundle2
import scmutil, util, extensions, hook, error, revset
import match as matchmod
import merge as mergemod
@@ -106,8 +106,14 @@
def getbundle(self, source, heads=None, common=None, bundlecaps=None,
format='HG10'):
- return exchange.getbundle(self._repo, source, heads=heads,
- common=common, bundlecaps=bundlecaps)
+ cg = exchange.getbundle(self._repo, source, heads=heads,
+ common=common, bundlecaps=bundlecaps)
+ if bundlecaps is not None and 'HG20' in bundlecaps:
+ # When requesting a bundle2, getbundle returns a stream to make the
+ # wire level function happier. We need to build a proper object
+ # from it in local peer.
+ cg = bundle2.unbundle20(self.ui, cg)
+ return cg
# TODO We might want to move the next two calls into legacypeer and add
# unbundle instead.