comparison mercurial/httppeer.py @ 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 167047ba3cfa
children d36440d84328
comparison
equal deleted inserted replaced
21073:83ce71ef7804 21074:f8a0d82b0463
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 from node import nullid 9 from node import nullid
10 from i18n import _ 10 from i18n import _
11 import tempfile
11 import changegroup, statichttprepo, error, httpconnection, url, util, wireproto 12 import changegroup, statichttprepo, error, httpconnection, url, util, wireproto
12 import os, urllib, urllib2, zlib, httplib 13 import os, urllib, urllib2, zlib, httplib
13 import errno, socket 14 import errno, socket
14 15
15 def zgenerator(f): 16 def zgenerator(f):
209 raise util.Abort(err.args[1]) 210 raise util.Abort(err.args[1])
210 finally: 211 finally:
211 fp.close() 212 fp.close()
212 os.unlink(tempname) 213 os.unlink(tempname)
213 214
215 def _calltwowaystream(self, cmd, fp, **args):
216 fh = None
217 filename = None
218 try:
219 # dump bundle to disk
220 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
221 fh = os.fdopen(fd, "wb")
222 d = fp.read(4096)
223 while d:
224 fh.write(d)
225 d = fp.read(4096)
226 fh.close()
227 # start http push
228 fp = httpconnection.httpsendfile(self.ui, filename, "rb")
229 headers = {'Content-Type': 'application/mercurial-0.1'}
230 return self._callstream(cmd, data=fp, headers=headers, **args)
231 finally:
232 if fh is not None:
233 fh.close()
234 os.unlink(filename)
235
214 def _callcompressable(self, cmd, **args): 236 def _callcompressable(self, cmd, **args):
215 stream = self._callstream(cmd, **args) 237 stream = self._callstream(cmd, **args)
216 return util.chunkbuffer(zgenerator(stream)) 238 return util.chunkbuffer(zgenerator(stream))
217 239
218 class httpspeer(httppeer): 240 class httpspeer(httppeer):