Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
30186:f7ed5af31242 | 30187:3e86261bf110 |
---|---|
147 def known(self, nodes): | 147 def known(self, nodes): |
148 return self._repo.known(nodes) | 148 return self._repo.known(nodes) |
149 | 149 |
150 def getbundle(self, source, heads=None, common=None, bundlecaps=None, | 150 def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
151 **kwargs): | 151 **kwargs): |
152 cg = exchange.getbundle(self._repo, source, heads=heads, | 152 chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
153 common=common, bundlecaps=bundlecaps, **kwargs) | 153 common=common, bundlecaps=bundlecaps, |
154 **kwargs) | |
155 cb = util.chunkbuffer(chunks) | |
156 | |
154 if bundlecaps is not None and 'HG20' in bundlecaps: | 157 if bundlecaps is not None and 'HG20' in bundlecaps: |
155 # When requesting a bundle2, getbundle returns a stream to make the | 158 # When requesting a bundle2, getbundle returns a stream to make the |
156 # wire level function happier. We need to build a proper object | 159 # wire level function happier. We need to build a proper object |
157 # from it in local peer. | 160 # from it in local peer. |
158 cg = bundle2.getunbundler(self.ui, cg) | 161 return bundle2.getunbundler(self.ui, cb) |
159 return cg | 162 else: |
163 return changegroup.getunbundler('01', cb, None) | |
160 | 164 |
161 # TODO We might want to move the next two calls into legacypeer and add | 165 # TODO We might want to move the next two calls into legacypeer and add |
162 # unbundle instead. | 166 # unbundle instead. |
163 | 167 |
164 def unbundle(self, cg, heads, url): | 168 def unbundle(self, cg, heads, url): |