mercurial/streamclone.py
changeset 38374 800f5a2c869e
parent 38373 ef692614e601
child 38783 e7aa113b14f7
equal deleted inserted replaced
38373:ef692614e601 38374:800f5a2c869e
   493     """actually emit the stream bundle"""
   493     """actually emit the stream bundle"""
   494     vfsmap = _makemap(repo)
   494     vfsmap = _makemap(repo)
   495     progress = repo.ui.makeprogress(_('bundle'), total=totalfilesize,
   495     progress = repo.ui.makeprogress(_('bundle'), total=totalfilesize,
   496                                     unit=_('bytes'))
   496                                     unit=_('bytes'))
   497     progress.update(0)
   497     progress.update(0)
   498     with maketempcopies() as copy:
   498     with maketempcopies() as copy, progress:
   499         try:
   499         # copy is delayed until we are in the try
   500             # copy is delayed until we are in the try
   500         entries = [_filterfull(e, copy, vfsmap) for e in entries]
   501             entries = [_filterfull(e, copy, vfsmap) for e in entries]
   501         yield None # this release the lock on the repository
   502             yield None # this release the lock on the repository
   502         seen = 0
   503             seen = 0
   503 
   504 
   504         for src, name, ftype, data in entries:
   505             for src, name, ftype, data in entries:
   505             vfs = vfsmap[src]
   506                 vfs = vfsmap[src]
   506             yield src
   507                 yield src
   507             yield util.uvarintencode(len(name))
   508                 yield util.uvarintencode(len(name))
   508             if ftype == _fileappend:
   509                 if ftype == _fileappend:
   509                 fp = vfs(name)
   510                     fp = vfs(name)
   510                 size = data
   511                     size = data
   511             elif ftype == _filefull:
   512                 elif ftype == _filefull:
   512                 fp = open(data, 'rb')
   513                     fp = open(data, 'rb')
   513                 size = util.fstat(fp).st_size
   514                     size = util.fstat(fp).st_size
   514             try:
   515                 try:
   515                 yield util.uvarintencode(size)
   516                     yield util.uvarintencode(size)
   516                 yield name
   517                     yield name
   517                 if size <= 65536:
   518                     if size <= 65536:
   518                     chunks = (fp.read(size),)
   519                         chunks = (fp.read(size),)
   519                 else:
   520                     else:
   520                     chunks = util.filechunkiter(fp, limit=size)
   521                         chunks = util.filechunkiter(fp, limit=size)
   521                 for chunk in chunks:
   522                     for chunk in chunks:
   522                     seen += len(chunk)
   523                         seen += len(chunk)
   523                     progress.update(seen)
   524                         progress.update(seen)
   524                     yield chunk
   525                         yield chunk
   525             finally:
   526                 finally:
   526                 fp.close()
   527                     fp.close()
       
   528         finally:
       
   529             progress.complete()
       
   530 
   527 
   531 def generatev2(repo):
   528 def generatev2(repo):
   532     """Emit content for version 2 of a streaming clone.
   529     """Emit content for version 2 of a streaming clone.
   533 
   530 
   534     the data stream consists the following entries:
   531     the data stream consists the following entries: