comparison mercurial/wireproto.py @ 11625:cdeb861335d5

protocol: wrap non-string protocol responses in classes
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 20 Jul 2010 20:53:33 +0200
parents 31d0a6d50ee2
children 04f76a954842
comparison
equal deleted inserted replaced
11624:67260651d09d 11625:cdeb861335d5
131 self.ui.status(_('remote: '), l) 131 self.ui.status(_('remote: '), l)
132 return ret 132 return ret
133 133
134 # server side 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 def dispatch(repo, proto, command): 144 def dispatch(repo, proto, command):
137 func, spec = commands[command] 145 func, spec = commands[command]
138 args = proto.getargs(spec) 146 args = proto.getargs(spec)
139 r = func(repo, proto, *args) 147 return func(repo, proto, *args)
140 if r != None:
141 proto.sendresponse(r)
142 148
143 def between(repo, proto, pairs): 149 def between(repo, proto, pairs):
144 pairs = [decodelist(p, '-') for p in pairs.split(" ")] 150 pairs = [decodelist(p, '-') for p in pairs.split(" ")]
145 r = [] 151 r = []
146 for b in repo.between(pairs): 152 for b in repo.between(pairs):
171 return ' '.join(caps) 177 return ' '.join(caps)
172 178
173 def changegroup(repo, proto, roots): 179 def changegroup(repo, proto, roots):
174 nodes = decodelist(roots) 180 nodes = decodelist(roots)
175 cg = repo.changegroup(nodes, 'serve') 181 cg = repo.changegroup(nodes, 'serve')
176 proto.sendstream(proto.groupchunks(cg)) 182 return streamres(proto.groupchunks(cg))
177 183
178 def changegroupsubset(repo, proto, bases, heads): 184 def changegroupsubset(repo, proto, bases, heads):
179 bases = decodelist(bases) 185 bases = decodelist(bases)
180 heads = decodelist(heads) 186 heads = decodelist(heads)
181 cg = repo.changegroupsubset(bases, heads, 'serve') 187 cg = repo.changegroupsubset(bases, heads, 'serve')
182 proto.sendstream(proto.groupchunks(cg)) 188 return streamres(proto.groupchunks(cg))
183 189
184 def heads(repo, proto): 190 def heads(repo, proto):
185 h = repo.heads() 191 h = repo.heads()
186 return encodelist(h) + "\n" 192 return encodelist(h) + "\n"
187 193
213 def pushkey(repo, proto, namespace, key, old, new): 219 def pushkey(repo, proto, namespace, key, old, new):
214 r = pushkey_.push(repo, namespace, key, old, new) 220 r = pushkey_.push(repo, namespace, key, old, new)
215 return '%s\n' % int(r) 221 return '%s\n' % int(r)
216 222
217 def stream(repo, proto): 223 def stream(repo, proto):
218 proto.sendstream(streamclone.stream_out(repo)) 224 return streamres(streamclone.stream_out(repo))
219 225
220 def unbundle(repo, proto, heads): 226 def unbundle(repo, proto, heads):
221 their_heads = decodelist(heads) 227 their_heads = decodelist(heads)
222 228
223 def check_heads(): 229 def check_heads():
257 lock=lock) 263 lock=lock)
258 except util.Abort, inst: 264 except util.Abort, inst:
259 sys.stderr.write("abort: %s\n" % inst) 265 sys.stderr.write("abort: %s\n" % inst)
260 finally: 266 finally:
261 lock.release() 267 lock.release()
262 proto.sendpushresponse(r) 268 return pushres(r)
263 269
264 finally: 270 finally:
265 fp.close() 271 fp.close()
266 os.unlink(tempname) 272 os.unlink(tempname)
267 273