comparison mercurial/commands.py @ 1980:dfb796786337

use HG10UN header for uncompressed bundle - use HG10UN instead of HG11 for uncompressed bundles header - check HG10BZ for compressed bundle - better error handling for invalid header some notes: - people who created uncompressed bundle will no longer be able to use them (it could be fixed with hand-editing) - older hg cannot detect an uncompressed bundle (bzip2 decompression will fail).
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Tue, 21 Mar 2006 06:03:33 +0100
parents d545fa1426b9
children 736b6c96bbbc
comparison
equal deleted inserted replaced
1979:d545fa1426b9 1980:dfb796786337
302 302
303 if compress: 303 if compress:
304 fh.write("HG10") 304 fh.write("HG10")
305 z = bz2.BZ2Compressor(9) 305 z = bz2.BZ2Compressor(9)
306 else: 306 else:
307 fh.write("HG11") 307 fh.write("HG10UN")
308 z = nocompress() 308 z = nocompress()
309 while 1: 309 while 1:
310 chunk = cg.read(4096) 310 chunk = cg.read(4096)
311 if not chunk: 311 if not chunk:
312 break 312 break
2567 Apply a compressed changegroup file generated by the bundle 2567 Apply a compressed changegroup file generated by the bundle
2568 command. 2568 command.
2569 """ 2569 """
2570 f = urllib.urlopen(fname) 2570 f = urllib.urlopen(fname)
2571 2571
2572 header = f.read(4) 2572 header = f.read(6)
2573 if header == "HG10": 2573 if not header.startswith("HG"):
2574 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
2575 elif not header.startswith("HG10"):
2576 raise util.Abort(_("%s: unknown bundle version") % fname)
2577 elif header == "HG10BZ":
2574 def generator(f): 2578 def generator(f):
2575 zd = bz2.BZ2Decompressor() 2579 zd = bz2.BZ2Decompressor()
2580 zd.decompress("BZ")
2576 for chunk in f: 2581 for chunk in f:
2577 yield zd.decompress(chunk) 2582 yield zd.decompress(chunk)
2578 elif header == "HG11": 2583 elif header == "HG10UN":
2579 def generator(f): 2584 def generator(f):
2580 for chunk in f: 2585 for chunk in f:
2581 yield chunk 2586 yield chunk
2582 else: 2587 else:
2583 raise util.Abort(_("%s: not a Mercurial bundle file") % fname) 2588 raise util.Abort(_("%s: unknown bundle compression type")
2589 % fname)
2584 gen = generator(util.filechunkiter(f, 4096)) 2590 gen = generator(util.filechunkiter(f, 4096))
2585 if repo.addchangegroup(util.chunkbuffer(gen)): 2591 if repo.addchangegroup(util.chunkbuffer(gen)):
2586 return 1 2592 return 1
2587 2593
2588 if opts['update']: 2594 if opts['update']: