192 |
192 |
193 def iscmd(cmd): |
193 def iscmd(cmd): |
194 return cmd in wireproto.commands |
194 return cmd in wireproto.commands |
195 |
195 |
196 def callhttp(repo, req, cmd): |
196 def callhttp(repo, req, cmd): |
197 p = webproto(req, repo.ui) |
197 proto = webproto(req, repo.ui) |
198 |
198 |
199 def genversion2(gen, engine, engineopts): |
199 def genversion2(gen, engine, engineopts): |
200 # application/mercurial-0.2 always sends a payload header |
200 # application/mercurial-0.2 always sends a payload header |
201 # identifying the compression engine. |
201 # identifying the compression engine. |
202 name = engine.wireprotosupport().name |
202 name = engine.wireprotosupport().name |
205 yield name |
205 yield name |
206 |
206 |
207 for chunk in gen: |
207 for chunk in gen: |
208 yield chunk |
208 yield chunk |
209 |
209 |
210 rsp = wireproto.dispatch(repo, p, cmd) |
210 rsp = wireproto.dispatch(repo, proto, cmd) |
211 if isinstance(rsp, bytes): |
211 if isinstance(rsp, bytes): |
212 req.respond(HTTP_OK, HGTYPE, body=rsp) |
212 req.respond(HTTP_OK, HGTYPE, body=rsp) |
213 return [] |
213 return [] |
214 elif isinstance(rsp, wireproto.streamres_legacy): |
214 elif isinstance(rsp, wireproto.streamres_legacy): |
215 gen = rsp.gen |
215 gen = rsp.gen |
218 elif isinstance(rsp, wireproto.streamres): |
218 elif isinstance(rsp, wireproto.streamres): |
219 gen = rsp.gen |
219 gen = rsp.gen |
220 |
220 |
221 # This code for compression should not be streamres specific. It |
221 # This code for compression should not be streamres specific. It |
222 # is here because we only compress streamres at the moment. |
222 # is here because we only compress streamres at the moment. |
223 mediatype, engine, engineopts = p.responsetype(rsp.prefer_uncompressed) |
223 mediatype, engine, engineopts = proto.responsetype( |
|
224 rsp.prefer_uncompressed) |
224 gen = engine.compressstream(gen, engineopts) |
225 gen = engine.compressstream(gen, engineopts) |
225 |
226 |
226 if mediatype == HGTYPE2: |
227 if mediatype == HGTYPE2: |
227 gen = genversion2(gen, engine, engineopts) |
228 gen = genversion2(gen, engine, engineopts) |
228 |
229 |
229 req.respond(HTTP_OK, mediatype) |
230 req.respond(HTTP_OK, mediatype) |
230 return gen |
231 return gen |
231 elif isinstance(rsp, wireproto.pushres): |
232 elif isinstance(rsp, wireproto.pushres): |
232 val = p.restore() |
233 val = proto.restore() |
233 rsp = '%d\n%s' % (rsp.res, val) |
234 rsp = '%d\n%s' % (rsp.res, val) |
234 req.respond(HTTP_OK, HGTYPE, body=rsp) |
235 req.respond(HTTP_OK, HGTYPE, body=rsp) |
235 return [] |
236 return [] |
236 elif isinstance(rsp, wireproto.pusherr): |
237 elif isinstance(rsp, wireproto.pusherr): |
237 # drain the incoming bundle |
238 # drain the incoming bundle |
238 req.drain() |
239 req.drain() |
239 p.restore() |
240 proto.restore() |
240 rsp = '0\n%s\n' % rsp.res |
241 rsp = '0\n%s\n' % rsp.res |
241 req.respond(HTTP_OK, HGTYPE, body=rsp) |
242 req.respond(HTTP_OK, HGTYPE, body=rsp) |
242 return [] |
243 return [] |
243 elif isinstance(rsp, wireproto.ooberror): |
244 elif isinstance(rsp, wireproto.ooberror): |
244 rsp = rsp.message |
245 rsp = rsp.message |