# HG changeset patch # User Eric Hopper # Date 1128375791 25200 # Node ID c3654cfaa77d92a8247b6224956307e88be0377a # Parent 965d1db5c95d5657666330eee71ea40645d6cff2 Fix hg unbundle chunking performance bug diff -r 965d1db5c95d -r c3654cfaa77d mercurial/commands.py --- 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