Mercurial > public > mercurial-scm > hg-stable
diff mercurial/wireproto.py @ 21075:438803e4bd97
bundle2: support for push over the wire
We use the new method defined in the past changeset to send a bundle2 stream and
receive one in reply. The http version is missing remote output support. This
will be done later using a bundle part.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 15 Apr 2014 11:53:10 -0400 |
parents | 0879352d67d8 |
children | d8dd19e09ed4 |
line wrap: on
line diff
--- a/mercurial/wireproto.py Tue Apr 15 17:53:52 2014 -0400 +++ b/mercurial/wireproto.py Tue Apr 15 11:53:10 2014 -0400 @@ -343,8 +343,12 @@ def unbundle(self, cg, heads, source): '''Send cg (a readable file-like object representing the changegroup to push, typically a chunkbuffer object) to the - remote server as a bundle. Return an integer indicating the - result of the push (see localrepository.addchangegroup()).''' + remote server as a bundle. + + When pushing a bundle10 stream, return an integer indicating the + result of the push (see localrepository.addchangegroup()). + + When pushing a bundle20 stream, return a bundle20 stream.''' if heads != ['force'] and self.capable('unbundlehash'): heads = encodelist(['hashed', @@ -352,18 +356,24 @@ else: heads = encodelist(heads) - ret, output = self._callpush("unbundle", cg, heads=heads) - if ret == "": - raise error.ResponseError( - _('push failed:'), output) - try: - ret = int(ret) - except ValueError: - raise error.ResponseError( - _('push failed (unexpected response):'), ret) + if util.safehasattr(cg, 'deltaheader'): + # this a bundle10, do the old style call sequence + ret, output = self._callpush("unbundle", cg, heads=heads) + if ret == "": + raise error.ResponseError( + _('push failed:'), output) + try: + ret = int(ret) + except ValueError: + raise error.ResponseError( + _('push failed (unexpected response):'), ret) - for l in output.splitlines(True): - self.ui.status(_('remote: '), l) + for l in output.splitlines(True): + self.ui.status(_('remote: '), l) + else: + # bundle2 push. Send a stream, fetch a stream. + stream = self._calltwowaystream('unbundle', cg, heads=heads) + ret = bundle2.unbundle20(self.ui, stream) return ret def debugwireargs(self, one, two, three=None, four=None, five=None): @@ -781,6 +791,10 @@ gen = exchange.readbundle(repo.ui, fp, None) r = exchange.unbundle(repo, gen, their_heads, 'serve', proto._client()) + if util.safehasattr(r, 'addpart'): + # The return looks streameable, we are in the bundle2 case and + # should return a stream. + return streamres(r.getchunks()) return pushres(r) finally: