Mercurial > public > mercurial-scm > hg-stable
diff mercurial/localrepo.py @ 30187:3e86261bf110
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 16 Oct 2016 10:38:52 -0700 |
parents | c15f06109b7a |
children | 1767723f71cf |
line wrap: on
line diff
--- a/mercurial/localrepo.py Thu Oct 13 01:30:14 2016 +0200 +++ b/mercurial/localrepo.py Sun Oct 16 10:38:52 2016 -0700 @@ -149,14 +149,18 @@ def getbundle(self, source, heads=None, common=None, bundlecaps=None, **kwargs): - cg = exchange.getbundle(self._repo, source, heads=heads, - common=common, bundlecaps=bundlecaps, **kwargs) + chunks = exchange.getbundlechunks(self._repo, source, heads=heads, + common=common, bundlecaps=bundlecaps, + **kwargs) + cb = util.chunkbuffer(chunks) + 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.getunbundler(self.ui, cg) - return cg + return bundle2.getunbundler(self.ui, cb) + else: + return changegroup.getunbundler('01', cb, None) # TODO We might want to move the next two calls into legacypeer and add # unbundle instead.