# HG changeset patch # User Matt Mackall # Date 2010-07-14 21:19:27 # Node ID 5d907fbb9703541e3a9ee3d66e50a0c64d88672f # Parent 1af96b0901168953f7fc95b27c92db8a3109e8b2 protocol: unify stream_out command diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -49,7 +49,10 @@ class webproto(object): 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 --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py --- a/mercurial/hgweb/protocol.py +++ b/mercurial/hgweb/protocol.py @@ -114,11 +114,3 @@ def unbundle(repo, req): 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 --git a/mercurial/sshserver.py b/mercurial/sshserver.py --- a/mercurial/sshserver.py +++ b/mercurial/sshserver.py @@ -67,6 +67,11 @@ class sshserver(object): 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 @@ class sshserver(object): 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 --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -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 @@ def pushkey(repo, proto, namespace, key, 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 @@ commands = { 'listkeys': (listkeys, 'namespace'), 'lookup': (lookup, 'key'), 'pushkey': (pushkey, 'namespace key old new'), + 'stream_out': (stream, ''), }