mercurial/changegroup.py
changeset 3667 8500a13ec44b
parent 3666 025f68f22ae2
child 3669 f4dc02d7fb71
equal deleted inserted replaced
3666:025f68f22ae2 3667:8500a13ec44b
    91     finally:
    91     finally:
    92         if fh is not None:
    92         if fh is not None:
    93             fh.close()
    93             fh.close()
    94         if cleanup is not None:
    94         if cleanup is not None:
    95             os.unlink(cleanup)
    95             os.unlink(cleanup)
       
    96 
       
    97 def readbundle(fh):
       
    98     header = fh.read(6)
       
    99     if not header.startswith("HG"):
       
   100         raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
       
   101     elif not header.startswith("HG10"):
       
   102         raise util.Abort(_("%s: unknown bundle version") % fname)
       
   103 
       
   104     if header == "HG10BZ":
       
   105         def generator(f):
       
   106             zd = bz2.BZ2Decompressor()
       
   107             zd.decompress("BZ")
       
   108             for chunk in util.filechunkiter(f, 4096):
       
   109                 yield zd.decompress(chunk)
       
   110         return util.chunkbuffer(generator(fh))
       
   111     elif header == "HG10UN":
       
   112         return fh
       
   113 
       
   114     raise util.Abort(_("%s: unknown bundle compression type")
       
   115                      % fname)