comparison 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
comparison
equal deleted inserted replaced
11591:0d9cb3f3b0a1 11592:26e0782b8380
136 return fp.read() 136 return fp.read()
137 finally: 137 finally:
138 # if using keepalive, allow connection to be reused 138 # if using keepalive, allow connection to be reused
139 fp.close() 139 fp.close()
140 140
141 def _abort(self, exception): 141 def _callpush(self, cmd, cg, **args):
142 raise exception
143
144 def _decompress(self, stream):
145 return util.chunkbuffer(zgenerator(stream))
146
147 def unbundle(self, cg, heads, source):
148 '''Send cg (a readable file-like object representing the
149 changegroup to push, typically a chunkbuffer object) to the
150 remote server as a bundle. Return an integer response code:
151 non-zero indicates a successful push (see
152 localrepository.addchangegroup()), and zero indicates either
153 error or nothing to push.'''
154 # have to stream bundle to a temp file because we do not have 142 # have to stream bundle to a temp file because we do not have
155 # http 1.1 chunked transfer. 143 # http 1.1 chunked transfer.
156 144
157 type = "" 145 type = ""
158 types = self.capable('unbundle') 146 types = self.capable('unbundle')
168 type = x 156 type = x
169 break 157 break
170 158
171 tempname = changegroup.writebundle(cg, None, type) 159 tempname = changegroup.writebundle(cg, None, type)
172 fp = url.httpsendfile(tempname, "rb") 160 fp = url.httpsendfile(tempname, "rb")
161 headers = {'Content-Type': 'application/mercurial-0.1'}
162
173 try: 163 try:
174 try: 164 try:
175 resp = self._call( 165 r = self._call(cmd, data=fp, headers=headers, **args)
176 'unbundle', data=fp, 166 return r.split('\n', 1)
177 headers={'Content-Type': 'application/mercurial-0.1'},
178 heads=' '.join(map(hex, heads)))
179 resp_code, output = resp.split('\n', 1)
180 try:
181 ret = int(resp_code)
182 except ValueError, err:
183 raise error.ResponseError(
184 _('push failed (unexpected response):'), resp)
185 for l in output.splitlines(True):
186 self.ui.status(_('remote: '), l)
187 return ret
188 except socket.error, err: 167 except socket.error, err:
189 if err.args[0] in (errno.ECONNRESET, errno.EPIPE): 168 if err.args[0] in (errno.ECONNRESET, errno.EPIPE):
190 raise util.Abort(_('push failed: %s') % err.args[1]) 169 raise util.Abort(_('push failed: %s') % err.args[1])
191 raise util.Abort(err.args[1]) 170 raise util.Abort(err.args[1])
192 finally: 171 finally:
193 fp.close() 172 fp.close()
194 os.unlink(tempname) 173 os.unlink(tempname)
174
175 def _abort(self, exception):
176 raise exception
177
178 def _decompress(self, stream):
179 return util.chunkbuffer(zgenerator(stream))
195 180
196 class httpsrepository(httprepository): 181 class httpsrepository(httprepository):
197 def __init__(self, ui, path): 182 def __init__(self, ui, path):
198 if not url.has_https: 183 if not url.has_https:
199 raise util.Abort(_('Python support for SSL and HTTPS ' 184 raise util.Abort(_('Python support for SSL and HTTPS '