##// END OF EJS Templates
wireproto: use maybecapturestdio() for push responses (API)...
Gregory Szorc -
r36084:caca3ac2 default
parent child Browse files
Show More
@@ -34,8 +34,7 httpoldcallstream = None
34 34 def putlfile(repo, proto, sha):
35 35 '''Server command for putting a largefile into a repository's local store
36 36 and into the user cache.'''
37 proto.redirect()
38
37 with proto.mayberedirectstdio() as output:
39 38 path = lfutil.storepath(repo, sha)
40 39 util.makedirs(os.path.dirname(path))
41 40 tmpfp = util.atomictempfile(path, createmode=repo.store.createmode)
@@ -50,11 +49,11 def putlfile(repo, proto, sha):
50 49 except IOError as e:
51 50 repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') %
52 51 (sha, e.strerror))
53 return wireproto.pushres(1)
52 return wireproto.pushres(1, output.getvalue() if output else '')
54 53 finally:
55 54 tmpfp.discard()
56 55
57 return wireproto.pushres(0)
56 return wireproto.pushres(0, output.getvalue() if output else '')
58 57
59 58 def getlfile(repo, proto, sha):
60 59 '''Server command for retrieving a largefile from the repository-local
@@ -510,16 +510,18 class pushres(object):
510 510
511 511 The call was successful and returned an integer contained in `self.res`.
512 512 """
513 def __init__(self, res):
513 def __init__(self, res, output):
514 514 self.res = res
515 self.output = output
515 516
516 517 class pusherr(object):
517 518 """wireproto reply: failure
518 519
519 520 The call failed. The `self.res` attribute contains the error message.
520 521 """
521 def __init__(self, res):
522 def __init__(self, res, output):
522 523 self.res = res
524 self.output = output
523 525
524 526 class ooberror(object):
525 527 """wireproto reply: failure of a batch of operation
@@ -997,9 +999,8 def stream(repo, proto):
997 999 def unbundle(repo, proto, heads):
998 1000 their_heads = decodelist(heads)
999 1001
1002 with proto.mayberedirectstdio() as output:
1000 1003 try:
1001 proto.redirect()
1002
1003 1004 exchange.check_heads(repo, their_heads, 'preparing changes')
1004 1005
1005 1006 # write bundle data to temporary file because it can be big
@@ -1014,9 +1015,9 def unbundle(repo, proto, heads):
1014 1015 and not bundle1allowed(repo, 'push')):
1015 1016 if proto.name == 'http':
1016 1017 # need to special case http because stderr do not get to
1017 # the http client on failed push so we need to abuse some
1018 # other error type to make sure the message get to the
1019 # user.
1018 # the http client on failed push so we need to abuse
1019 # some other error type to make sure the message get to
1020 # the user.
1020 1021 return ooberror(bundle2required)
1021 1022 raise error.Abort(bundle2requiredmain,
1022 1023 hint=bundle2requiredhint)
@@ -1024,10 +1025,10 def unbundle(repo, proto, heads):
1024 1025 r = exchange.unbundle(repo, gen, their_heads, 'serve',
1025 1026 proto._client())
1026 1027 if util.safehasattr(r, 'addpart'):
1027 # The return looks streamable, we are in the bundle2 case and
1028 # should return a stream.
1028 # The return looks streamable, we are in the bundle2 case
1029 # and should return a stream.
1029 1030 return streamres_legacy(gen=r.getchunks())
1030 return pushres(r)
1031 return pushres(r, output.getvalue() if output else '')
1031 1032
1032 1033 finally:
1033 1034 fp.close()
@@ -1046,9 +1047,10 def unbundle(repo, proto, heads):
1046 1047 util.stderr.write("abort: %s\n" % exc)
1047 1048 if exc.hint is not None:
1048 1049 util.stderr.write("(%s)\n" % exc.hint)
1049 return pushres(0)
1050 return pushres(0, output.getvalue() if output else '')
1050 1051 except error.PushRaced:
1051 return pusherr(str(exc))
1052 return pusherr(str(exc),
1053 output.getvalue() if output else '')
1052 1054
1053 1055 bundler = bundle2.bundle20(repo.ui)
1054 1056 for out in getattr(exc, '_bundle2salvagedoutput', ()):
@@ -1066,7 +1068,8 def unbundle(repo, proto, heads):
1066 1068 part = bundler.newpart('error:pushkey')
1067 1069 part.addparam('in-reply-to', exc.partid)
1068 1070 if exc.namespace is not None:
1069 part.addparam('namespace', exc.namespace, mandatory=False)
1071 part.addparam('namespace', exc.namespace,
1072 mandatory=False)
1070 1073 if exc.key is not None:
1071 1074 part.addparam('key', exc.key, mandatory=False)
1072 1075 if exc.new is not None:
@@ -320,15 +320,13 def _callhttp(repo, req, proto, cmd):
320 320 req.respond(HTTP_OK, mediatype)
321 321 return gen
322 322 elif isinstance(rsp, wireproto.pushres):
323 val = proto.restore()
324 rsp = '%d\n%s' % (rsp.res, val)
323 rsp = '%d\n%s' % (rsp.res, rsp.output)
325 324 req.respond(HTTP_OK, HGTYPE, body=rsp)
326 325 return []
327 326 elif isinstance(rsp, wireproto.pusherr):
328 327 # This is the httplib workaround documented in _handlehttperror().
329 328 req.drain()
330 329
331 proto.restore()
332 330 rsp = '0\n%s\n' % rsp.res
333 331 req.respond(HTTP_OK, HGTYPE, body=rsp)
334 332 return []
General Comments 0
You need to be logged in to leave comments. Login now