Show More
@@ -48,13 +48,20 b' class webproto(object):' | |||
|
48 | 48 | self.response = s |
|
49 | 49 | def sendstream(self, source): |
|
50 | 50 | self.req.respond(HTTP_OK, HGTYPE) |
|
51 | for chunk in source: | |
|
52 |
self.req.write( |
|
|
53 |
def sendpushresponse(self, r |
|
|
51 | for chunk in source.gen: | |
|
52 | self.req.write(chunk) | |
|
53 | def sendpushresponse(self, rsp): | |
|
54 | 54 | val = sys.stdout.getvalue() |
|
55 | 55 | sys.stdout, sys.stderr = self.oldio |
|
56 | 56 | self.req.respond(HTTP_OK, HGTYPE) |
|
57 |
self.response = '%d\n%s' % (r |
|
|
57 | self.response = '%d\n%s' % (rsp.res, val) | |
|
58 | ||
|
59 | handlers = { | |
|
60 | str: sendresponse, | |
|
61 | wireproto.streamres: sendstream, | |
|
62 | wireproto.pushres: sendpushresponse, | |
|
63 | } | |
|
64 | ||
|
58 | 65 | def _client(self): |
|
59 | 66 | return 'remote:%s:%s:%s' % ( |
|
60 | 67 | self.req.env.get('wsgi.url_scheme') or 'http', |
@@ -66,5 +73,6 b' def iscmd(cmd):' | |||
|
66 | 73 | |
|
67 | 74 | def call(repo, req, cmd): |
|
68 | 75 | p = webproto(req) |
|
69 | wireproto.dispatch(repo, p, cmd) | |
|
70 | yield p.response | |
|
76 | rsp = wireproto.dispatch(repo, p, cmd) | |
|
77 | webproto.handlers[rsp.__class__](p, rsp) | |
|
78 | return [p.response] |
@@ -72,13 +72,13 b' class sshserver(object):' | |||
|
72 | 72 | self.fout.flush() |
|
73 | 73 | |
|
74 | 74 | def sendstream(self, source): |
|
75 | for chunk in source: | |
|
75 | for chunk in source.gen: | |
|
76 | 76 | self.fout.write(chunk) |
|
77 | 77 | self.fout.flush() |
|
78 | 78 | |
|
79 |
def sendpushresponse(self, r |
|
|
79 | def sendpushresponse(self, rsp): | |
|
80 | 80 | self.sendresponse('') |
|
81 |
self.sendresponse(str(r |
|
|
81 | self.sendresponse(str(rsp.res)) | |
|
82 | 82 | |
|
83 | 83 | def serve_forever(self): |
|
84 | 84 | try: |
@@ -89,10 +89,17 b' class sshserver(object):' | |||
|
89 | 89 | self.lock.release() |
|
90 | 90 | sys.exit(0) |
|
91 | 91 | |
|
92 | handlers = { | |
|
93 | str: sendresponse, | |
|
94 | wireproto.streamres: sendstream, | |
|
95 | wireproto.pushres: sendpushresponse, | |
|
96 | } | |
|
97 | ||
|
92 | 98 | def serve_one(self): |
|
93 | 99 | cmd = self.fin.readline()[:-1] |
|
94 | 100 | if cmd and cmd in wireproto.commands: |
|
95 | wireproto.dispatch(self.repo, self, cmd) | |
|
101 | rsp = wireproto.dispatch(self.repo, self, cmd) | |
|
102 | self.handlers[rsp.__class__](self, rsp) | |
|
96 | 103 | elif cmd: |
|
97 | 104 | impl = getattr(self, 'do_' + cmd, None) |
|
98 | 105 | if impl: |
@@ -133,12 +133,18 b' class wirerepository(repo.repository):' | |||
|
133 | 133 | |
|
134 | 134 | # server side |
|
135 | 135 | |
|
136 | class streamres(object): | |
|
137 | def __init__(self, gen): | |
|
138 | self.gen = gen | |
|
139 | ||
|
140 | class pushres(object): | |
|
141 | def __init__(self, res): | |
|
142 | self.res = res | |
|
143 | ||
|
136 | 144 | def dispatch(repo, proto, command): |
|
137 | 145 | func, spec = commands[command] |
|
138 | 146 | args = proto.getargs(spec) |
|
139 |
r |
|
|
140 | if r != None: | |
|
141 | proto.sendresponse(r) | |
|
147 | return func(repo, proto, *args) | |
|
142 | 148 | |
|
143 | 149 | def between(repo, proto, pairs): |
|
144 | 150 | pairs = [decodelist(p, '-') for p in pairs.split(" ")] |
@@ -173,13 +179,13 b' def capabilities(repo, proto):' | |||
|
173 | 179 | def changegroup(repo, proto, roots): |
|
174 | 180 | nodes = decodelist(roots) |
|
175 | 181 | cg = repo.changegroup(nodes, 'serve') |
|
176 |
|
|
|
182 | return streamres(proto.groupchunks(cg)) | |
|
177 | 183 | |
|
178 | 184 | def changegroupsubset(repo, proto, bases, heads): |
|
179 | 185 | bases = decodelist(bases) |
|
180 | 186 | heads = decodelist(heads) |
|
181 | 187 | cg = repo.changegroupsubset(bases, heads, 'serve') |
|
182 |
|
|
|
188 | return streamres(proto.groupchunks(cg)) | |
|
183 | 189 | |
|
184 | 190 | def heads(repo, proto): |
|
185 | 191 | h = repo.heads() |
@@ -215,7 +221,7 b' def pushkey(repo, proto, namespace, key,' | |||
|
215 | 221 | return '%s\n' % int(r) |
|
216 | 222 | |
|
217 | 223 | def stream(repo, proto): |
|
218 |
|
|
|
224 | return streamres(streamclone.stream_out(repo)) | |
|
219 | 225 | |
|
220 | 226 | def unbundle(repo, proto, heads): |
|
221 | 227 | their_heads = decodelist(heads) |
@@ -259,7 +265,7 b' def unbundle(repo, proto, heads):' | |||
|
259 | 265 | sys.stderr.write("abort: %s\n" % inst) |
|
260 | 266 | finally: |
|
261 | 267 | lock.release() |
|
262 |
|
|
|
268 | return pushres(r) | |
|
263 | 269 | |
|
264 | 270 | finally: |
|
265 | 271 | fp.close() |
General Comments 0
You need to be logged in to leave comments.
Login now