Mercurial > public > mercurial-scm > hg-stable
diff mercurial/changegroup.py @ 3660: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 Wed Nov 15 15:51:58 2006 -0600 +++ b/mercurial/changegroup.py Wed Nov 15 15:51:58 2006 -0600 @@ -93,3 +93,23 @@ 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)