# HG changeset patch # User Matt Mackall # Date 1282768386 18000 # Node ID 210049a8d16e25e6fe56bd8940b41eed9e38743c # Parent 270fb4d39153afbadce2c2b38383f4b82826c247 bundle: unify/refactor unbundle/readbundle diff -r 270fb4d39153 -r 210049a8d16e mercurial/changegroup.py --- a/mercurial/changegroup.py Wed Aug 25 15:33:05 2010 -0500 +++ b/mercurial/changegroup.py Wed Aug 25 15:33:06 2010 -0500 @@ -138,24 +138,24 @@ raise util.Abort("unknown bundle compression '%s'" % alg) return generator(fh) -def unbundle(header, fh): - if not header.startswith('HG'): - def fixup(f, h): - yield h - for x in f: - yield x - fh = fixup(f, h) - header = "HG10UN" - - alg = header[4:6] - return util.chunkbuffer(decompressor(fh, alg)) - def readbundle(fh, fname): header = fh.read(6) - if not header.startswith('HG'): - raise util.Abort(_('%s: not a Mercurial bundle file') % fname) - if not header.startswith('HG10'): - raise util.Abort(_('%s: unknown bundle version') % fname) - elif header not in bundletypes: - raise util.Abort(_('%s: unknown bundle compression type') % fname) - return unbundle(header, fh) + + if not fname: + fname = "stream" + if not header.startswith('HG') and header.startswith('\0'): + # headerless bundle, clean things up + def fixup(f, h): + yield h + for x in f: + yield x + fh = fixup(fh, header) + header = "HG10UN" + + magic, version, alg = header[0:2], header[2:4], header[4:6] + + if magic != 'HG': + raise util.Abort(_('%s: not a Mercurial bundle') % fname) + if version != '10': + raise util.Abort(_('%s: unknown bundle version %s') % (fname, version)) + return util.chunkbuffer(decompressor(fh, alg)) diff -r 270fb4d39153 -r 210049a8d16e mercurial/wireproto.py --- a/mercurial/wireproto.py Wed Aug 25 15:33:05 2010 -0500 +++ b/mercurial/wireproto.py Wed Aug 25 15:33:06 2010 -0500 @@ -294,13 +294,7 @@ # push can proceed fp.seek(0) - header = fp.read(6) - if header.startswith('HG'): - if not header.startswith('HG10'): - raise ValueError('unknown bundle version') - elif header not in changegroupmod.bundletypes: - raise ValueError('unknown bundle compression type') - gen = changegroupmod.unbundle(header, fp) + gen = changegroupmod.readbundle(fp, None) try: r = repo.addchangegroup(gen, 'serve', proto._client(),