Mercurial > hg-stable
changeset 21074:f8a0d82b0463
httppeer: support for _calltwowaystream
This new method is now supported by http too.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 15 Apr 2014 17:53:52 -0400 |
parents | 83ce71ef7804 |
children | 438803e4bd97 |
files | mercurial/httppeer.py |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httppeer.py Tue Apr 15 17:18:35 2014 -0400 +++ b/mercurial/httppeer.py Tue Apr 15 17:53:52 2014 -0400 @@ -8,6 +8,7 @@ from node import nullid from i18n import _ +import tempfile import changegroup, statichttprepo, error, httpconnection, url, util, wireproto import os, urllib, urllib2, zlib, httplib import errno, socket @@ -211,6 +212,27 @@ fp.close() os.unlink(tempname) + def _calltwowaystream(self, cmd, fp, **args): + fh = None + filename = None + try: + # dump bundle to disk + fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") + fh = os.fdopen(fd, "wb") + d = fp.read(4096) + while d: + fh.write(d) + d = fp.read(4096) + fh.close() + # start http push + fp = httpconnection.httpsendfile(self.ui, filename, "rb") + headers = {'Content-Type': 'application/mercurial-0.1'} + return self._callstream(cmd, data=fp, headers=headers, **args) + finally: + if fh is not None: + fh.close() + os.unlink(filename) + def _callcompressable(self, cmd, **args): stream = self._callstream(cmd, **args) return util.chunkbuffer(zgenerator(stream))