changeset 1374:c3654cfaa77d

Fix hg unbundle chunking performance bug
author Eric Hopper <hopper@omnifarious.org>
date Mon, 03 Oct 2005 14:43:11 -0700
parents 965d1db5c95d
children f2b00be33e2c
files mercurial/commands.py
diffstat 1 files changed, 7 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Mon Oct 03 13:45:59 2005 -0700
+++ b/mercurial/commands.py	Mon Oct 03 14:43:11 2005 -0700
@@ -1681,22 +1681,14 @@
     if f.read(4) != "HG10":
         raise util.Abort("%s: not a Mercurial bundle file" % fname)
 
-    class bzread:
-        def __init__(self, f):
-            self.zd = bz2.BZ2Decompressor()
-            self.f = f
-            self.buf = ""
-        def read(self, l):
-            while l > len(self.buf):
-                r = self.f.read(4096)
-                if r:
-                    self.buf += self.zd.decompress(r)
-                else:
-                    break
-            d, self.buf = self.buf[:l], self.buf[l:]
-            return d
+    def bzgenerator(f):
+        zd = bz2.BZ2Decompressor()
+        for chunk in f:
+            yield zd.decompress(chunk)
+        yield zd.flush()
 
-    repo.addchangegroup(bzread(f))
+    bzgen = bzgenerator(util.filechunkiter(f, 4096))
+    repo.addchangegroup(util.chunkbuffer(bzgen))
 
 def undo(ui, repo):
     """undo the last commit or pull