protocol: unify stream_out command
authorMatt Mackall <mpm@selenic.com>
Wed, 14 Jul 2010 16:19:27 -0500
changeset 11585 5d907fbb9703
parent 11584 1af96b090116
child 11586 ddaaaa23bb8f
protocol: unify stream_out command
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/protocol.py
mercurial/sshserver.py
mercurial/wireproto.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
--- 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)
--- 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()
--- 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, ''),
 }