comparison mercurial/streamclone.py @ 27882:319b0bf6ecc9

streamclone: extract code for reading header fields So it can be called from another consumer in a future patch.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 14 Jan 2016 22:48:54 -0800
parents ed9950ba091e
children 1d29893240cc
comparison
equal deleted inserted replaced
27881:ffa599f3f503 27882:319b0bf6ecc9
327 repo.ui.progress(_('clone'), None) 327 repo.ui.progress(_('clone'), None)
328 repo.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % 328 repo.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
329 (util.bytecount(bytecount), elapsed, 329 (util.bytecount(bytecount), elapsed,
330 util.bytecount(bytecount / elapsed))) 330 util.bytecount(bytecount / elapsed)))
331 331
332 def applybundlev1(repo, fp): 332 def readbundle1header(fp):
333 """Apply the content from a stream clone bundle version 1.
334
335 We assume the 4 byte header has been read and validated and the file handle
336 is at the 2 byte compression identifier.
337 """
338 if len(repo):
339 raise error.Abort(_('cannot apply stream clone bundle on non-empty '
340 'repo'))
341
342 compression = fp.read(2) 333 compression = fp.read(2)
343 if compression != 'UN': 334 if compression != 'UN':
344 raise error.Abort(_('only uncompressed stream clone bundles are ' 335 raise error.Abort(_('only uncompressed stream clone bundles are '
345 'supported; got %s') % compression) 336 'supported; got %s') % compression)
346 337
351 if not requires.endswith('\0'): 342 if not requires.endswith('\0'):
352 raise error.Abort(_('malformed stream clone bundle: ' 343 raise error.Abort(_('malformed stream clone bundle: '
353 'requirements not properly encoded')) 344 'requirements not properly encoded'))
354 345
355 requirements = set(requires.rstrip('\0').split(',')) 346 requirements = set(requires.rstrip('\0').split(','))
347
348 return filecount, bytecount, requirements
349
350 def applybundlev1(repo, fp):
351 """Apply the content from a stream clone bundle version 1.
352
353 We assume the 4 byte header has been read and validated and the file handle
354 is at the 2 byte compression identifier.
355 """
356 if len(repo):
357 raise error.Abort(_('cannot apply stream clone bundle on non-empty '
358 'repo'))
359
360 filecount, bytecount, requirements = readbundle1header(fp)
356 missingreqs = requirements - repo.supportedformats 361 missingreqs = requirements - repo.supportedformats
357 if missingreqs: 362 if missingreqs:
358 raise error.Abort(_('unable to apply stream clone: ' 363 raise error.Abort(_('unable to apply stream clone: '
359 'unsupported format: %s') % 364 'unsupported format: %s') %
360 ', '.join(sorted(missingreqs))) 365 ', '.join(sorted(missingreqs)))