# HG changeset patch # User Matt Mackall # Date 1279142367 18000 # Node ID 5d907fbb9703541e3a9ee3d66e50a0c64d88672f # Parent 1af96b0901168953f7fc95b27c92db8a3109e8b2 protocol: unify stream_out command diff -r 1af96b090116 -r 5d907fbb9703 mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py Wed Jul 14 15:43:20 2010 -0500 +++ b/mercurial/hgweb/hgweb_mod.py Wed Jul 14 16:19:27 2010 -0500 @@ -49,7 +49,10 @@ break self.req.write(z.compress(chunk)) self.req.write(z.flush()) - + def sendstream(self, source): + self.req.respond(HTTP_OK, HGTYPE) + for chunk in source: + self.req.write(chunk) def respond(self, s): self.req.respond(HTTP_OK, HGTYPE, length=len(s)) self.response = s diff -r 1af96b090116 -r 5d907fbb9703 mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py Wed Jul 14 15:43:20 2010 -0500 +++ b/mercurial/hgweb/protocol.py Wed Jul 14 16:19:27 2010 -0500 @@ -114,11 +114,3 @@ finally: fp.close() os.unlink(tempname) - -def stream_out(repo, req): - req.respond(HTTP_OK, HGTYPE) - try: - for chunk in streamclone.stream_out(repo): - yield chunk - except streamclone.StreamException, inst: - yield str(inst) diff -r 1af96b090116 -r 5d907fbb9703 mercurial/sshserver.py --- a/mercurial/sshserver.py Wed Jul 14 15:43:20 2010 -0500 +++ b/mercurial/sshserver.py Wed Jul 14 16:19:27 2010 -0500 @@ -67,6 +67,11 @@ self.fout.flush() + def sendstream(self, source): + for chunk in source: + self.fout.write(chunk) + self.fout.flush() + def serve_forever(self): try: while self.serve_one(): @@ -177,12 +182,3 @@ finally: fp.close() os.unlink(tempname) - - def do_stream_out(self): - try: - for chunk in streamclone.stream_out(self.repo): - self.fout.write(chunk) - self.fout.flush() - except streamclone.StreamException, inst: - self.fout.write(str(inst)) - self.fout.flush() diff -r 1af96b090116 -r 5d907fbb9703 mercurial/wireproto.py --- a/mercurial/wireproto.py Wed Jul 14 15:43:20 2010 -0500 +++ b/mercurial/wireproto.py Wed Jul 14 16:19:27 2010 -0500 @@ -7,7 +7,7 @@ from i18n import _ from node import bin, hex -import urllib +import urllib, streamclone import pushkey as pushkey_ def dispatch(repo, proto, command): @@ -77,6 +77,12 @@ r = pushkey_.push(repo, namespace, key, old, new) return '%s\n' % int(r) +def stream(repo, proto): + try: + proto.sendstream(streamclone.stream_out(repo)) + except streamclone.StreamException, inst: + return str(inst) + commands = { 'between': (between, 'pairs'), 'branchmap': (branchmap, ''), @@ -87,4 +93,5 @@ 'listkeys': (listkeys, 'namespace'), 'lookup': (lookup, 'key'), 'pushkey': (pushkey, 'namespace key old new'), + 'stream_out': (stream, ''), }