Mercurial > hg > mercurial-crew-with-dirclash
diff mercurial/changegroup.py @ 3667:8500a13ec44b
create a readbundle function
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 15 Nov 2006 15:51:58 -0600 |
parents | 025f68f22ae2 |
children | f4dc02d7fb71 |
line wrap: on
line diff
--- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -93,3 +93,23 @@ def writebundle(cg, filename, compress): fh.close() if cleanup is not None: os.unlink(cleanup) + +def readbundle(fh): + header = fh.read(6) + if not header.startswith("HG"): + raise util.Abort(_("%s: not a Mercurial bundle file") % fname) + elif not header.startswith("HG10"): + raise util.Abort(_("%s: unknown bundle version") % fname) + + if header == "HG10BZ": + def generator(f): + zd = bz2.BZ2Decompressor() + zd.decompress("BZ") + for chunk in util.filechunkiter(f, 4096): + yield zd.decompress(chunk) + return util.chunkbuffer(generator(fh)) + elif header == "HG10UN": + return fh + + raise util.Abort(_("%s: unknown bundle compression type") + % fname)