Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 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 | 27add82ad845 |
comparison
equal
deleted
inserted
replaced
1373:965d1db5c95d | 1374:c3654cfaa77d |
---|---|
1679 f = urllib.urlopen(fname) | 1679 f = urllib.urlopen(fname) |
1680 | 1680 |
1681 if f.read(4) != "HG10": | 1681 if f.read(4) != "HG10": |
1682 raise util.Abort("%s: not a Mercurial bundle file" % fname) | 1682 raise util.Abort("%s: not a Mercurial bundle file" % fname) |
1683 | 1683 |
1684 class bzread: | 1684 def bzgenerator(f): |
1685 def __init__(self, f): | 1685 zd = bz2.BZ2Decompressor() |
1686 self.zd = bz2.BZ2Decompressor() | 1686 for chunk in f: |
1687 self.f = f | 1687 yield zd.decompress(chunk) |
1688 self.buf = "" | 1688 yield zd.flush() |
1689 def read(self, l): | 1689 |
1690 while l > len(self.buf): | 1690 bzgen = bzgenerator(util.filechunkiter(f, 4096)) |
1691 r = self.f.read(4096) | 1691 repo.addchangegroup(util.chunkbuffer(bzgen)) |
1692 if r: | |
1693 self.buf += self.zd.decompress(r) | |
1694 else: | |
1695 break | |
1696 d, self.buf = self.buf[:l], self.buf[l:] | |
1697 return d | |
1698 | |
1699 repo.addchangegroup(bzread(f)) | |
1700 | 1692 |
1701 def undo(ui, repo): | 1693 def undo(ui, repo): |
1702 """undo the last commit or pull | 1694 """undo the last commit or pull |
1703 | 1695 |
1704 Roll back the last pull or commit transaction on the | 1696 Roll back the last pull or commit transaction on the |