Exemple #1
0
    def _callpush(self, cmd, cg, **args):
        # have to stream bundle to a temp file because we do not have
        # http 1.1 chunked transfer.

        types = self.capable('unbundle')
        try:
            types = types.split(',')
        except AttributeError:
            # servers older than d1b16a746db6 will send 'unbundle' as a
            # boolean capability. They only support headerless/uncompressed
            # bundles.
            types = [""]
        for x in types:
            if x in changegroup.bundletypes:
                type = x
                break

        tempname = changegroup.writebundle(self.ui, cg, None, type)
        fp = httpconnection.httpsendfile(self.ui, tempname, "rb")
        headers = {'Content-Type': 'application/mercurial-0.1'}

        try:
            try:
                r = self._call(cmd, data=fp, headers=headers, **args)
                vals = r.split('\n', 1)
                if len(vals) < 2:
                    raise error.ResponseError(_("unexpected response:"), r)
                return vals
            except socket.error, err:
                if err.args[0] in (errno.ECONNRESET, errno.EPIPE):
                    raise util.Abort(_('push failed: %s') % err.args[1])
                raise util.Abort(err.args[1])
        finally:
            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)
Exemple #3
0
 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)