[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mercurial-devel
Subject:    [PATCH 1 of 4] streamclone yields chunks instead of accepting a
From:       Dirkjan Ochtman <dirkjan () ochtman ! nl>
Date:       2008-06-29 13:24:40
Message-ID: b9d6ab1875231120c01f.1214745880 () enrai ! xavamedia ! nl
[Download RAW message or body]

# HG changeset patch
# User Dirkjan Ochtman <dirkjan@ochtman.nl>
# Date 1214742001 -7200
# Node ID b9d6ab1875231120c01fe804178aa2798e114d44
# Parent  b4b7261164d5755b83ca281ddefbda91a959d36d
streamclone yields chunks instead of accepting a file-like object

diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -205,4 +205,5 @@
 
 def stream_out(repo, req):
     req.respond(HTTP_OK, HGTYPE)
-    streamclone.stream_out(repo, req, untrusted=True)
+    for chunk in streamclone.stream_out(repo, untrusted=True):
+        req.write(chunk)
diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py
--- a/mercurial/sshserver.py
+++ b/mercurial/sshserver.py
@@ -204,4 +204,6 @@
                 os.unlink(tempname)
 
     def do_stream_out(self):
-        streamclone.stream_out(self.repo, self.fout)
+        for chunk in streamclone.stream_out(self.repo):
+            self.fout.write(chunk)
+        self.fout.flush()
diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -51,12 +51,12 @@
 #
 #   server writes out raw file data.
 
-def stream_out(repo, fileobj, untrusted=False):
+def stream_out(repo, untrusted=False):
     '''stream out all metadata files in repository.
     writes to file-like object, must support write() and optional flush().'''
 
     if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
-        fileobj.write('1\n')
+        yield '1\n'
         return
 
     # get consistent snapshot of repo. lock during scan so lock not
@@ -67,10 +67,10 @@
             repolock = repo.lock()
         except (lock.LockHeld, lock.LockUnavailable), inst:
             repo.ui.warn('locking the repository failed: %s\n' % (inst,))
-            fileobj.write('2\n')
+            yield '2\n'
             return
 
-        fileobj.write('0\n')
+        yield '0\n'
         repo.ui.debug('scanning\n')
         entries = []
         total_bytes = 0
@@ -83,11 +83,9 @@
 
     repo.ui.debug('%d files, %d bytes to transfer\n' %
                   (len(entries), total_bytes))
-    fileobj.write('%d %d\n' % (len(entries), total_bytes))
+    yield '%d %d\n' % (len(entries), total_bytes)
     for name, size in entries:
         repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
-        fileobj.write('%s\0%d\n' % (name, size))
+        yield '%s\0%d\n' % (name, size)
         for chunk in util.filechunkiter(repo.sopener(name), limit=size):
-            fileobj.write(chunk)
-    flush = getattr(fileobj, 'flush', None)
-    if flush: flush()
+            yield chunk
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@selenic.com
http://selenic.com/mailman/listinfo/mercurial-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic