Mercurial > public > mercurial-scm > hg-stable
diff mercurial/httprepo.py @ 11592:26e0782b8380
protocol: unify client unbundle support
- introduce _callpush helper
- factor out differences in result handling into helpers
- unify
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 14 Jul 2010 17:12:18 -0500 |
parents | 0d9cb3f3b0a1 |
children | 05deba16c5d5 |
line wrap: on
line diff
--- a/mercurial/httprepo.py Wed Jul 14 17:09:31 2010 -0500 +++ b/mercurial/httprepo.py Wed Jul 14 17:12:18 2010 -0500 @@ -138,19 +138,7 @@ # if using keepalive, allow connection to be reused fp.close() - def _abort(self, exception): - raise exception - - def _decompress(self, stream): - return util.chunkbuffer(zgenerator(stream)) - - 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 response code: - non-zero indicates a successful push (see - localrepository.addchangegroup()), and zero indicates either - error or nothing to push.''' + def _callpush(self, cmd, cg, **args): # have to stream bundle to a temp file because we do not have # http 1.1 chunked transfer. @@ -170,21 +158,12 @@ tempname = changegroup.writebundle(cg, None, type) fp = url.httpsendfile(tempname, "rb") + headers = {'Content-Type': 'application/mercurial-0.1'} + try: try: - resp = self._call( - 'unbundle', data=fp, - headers={'Content-Type': 'application/mercurial-0.1'}, - heads=' '.join(map(hex, heads))) - resp_code, output = resp.split('\n', 1) - try: - ret = int(resp_code) - except ValueError, err: - raise error.ResponseError( - _('push failed (unexpected response):'), resp) - for l in output.splitlines(True): - self.ui.status(_('remote: '), l) - return ret + r = self._call(cmd, data=fp, headers=headers, **args) + return r.split('\n', 1) except socket.error, err: if err.args[0] in (errno.ECONNRESET, errno.EPIPE): raise util.Abort(_('push failed: %s') % err.args[1]) @@ -193,6 +172,12 @@ fp.close() os.unlink(tempname) + def _abort(self, exception): + raise exception + + def _decompress(self, stream): + return util.chunkbuffer(zgenerator(stream)) + class httpsrepository(httprepository): def __init__(self, ui, path): if not url.has_https: