mercurial/streamclone.py
changeset 50632 3416b46320dc
parent 50631 1415e17ea20f
child 50633 c90ea9bbf327
equal deleted inserted replaced
50631:1415e17ea20f 50632:3416b46320dc
   618     assert repo.vfs not in vfsmap.values()
   618     assert repo.vfs not in vfsmap.values()
   619 
   619 
   620     return vfsmap
   620     return vfsmap
   621 
   621 
   622 
   622 
   623 def _emit2(repo, entries, totalfilesize):
   623 def _emit2(repo, entries):
   624     """actually emit the stream bundle"""
   624     """actually emit the stream bundle"""
   625     vfsmap = _makemap(repo)
   625     vfsmap = _makemap(repo)
   626     # we keep repo.vfs out of the on purpose, ther are too many danger there
   626     # we keep repo.vfs out of the on purpose, ther are too many danger there
   627     # (eg: .hg/hgrc),
   627     # (eg: .hg/hgrc),
   628     #
   628     #
   631     if repo.vfs in vfsmap.values():
   631     if repo.vfs in vfsmap.values():
   632         raise error.ProgrammingError(
   632         raise error.ProgrammingError(
   633             b'repo.vfs must not be added to vfsmap for security reasons'
   633             b'repo.vfs must not be added to vfsmap for security reasons'
   634         )
   634         )
   635 
   635 
       
   636     # translate the vfs one
       
   637     entries = [(vfs_key, vfsmap[vfs_key], e) for (vfs_key, e) in entries]
       
   638 
       
   639     file_count = totalfilesize = 0
       
   640     # record the expected size of every file
       
   641     for k, vfs, e in entries:
       
   642         for f in e.files():
       
   643             file_count += 1
       
   644             totalfilesize += f.file_size(vfs)
       
   645 
   636     progress = repo.ui.makeprogress(
   646     progress = repo.ui.makeprogress(
   637         _(b'bundle'), total=totalfilesize, unit=_(b'bytes')
   647         _(b'bundle'), total=totalfilesize, unit=_(b'bytes')
   638     )
   648     )
   639     progress.update(0)
   649     progress.update(0)
   640     with TempCopyManager() as copy, progress:
   650     with TempCopyManager() as copy, progress:
   641         # copy is delayed until we are in the try
   651         # create a copy of volatile files
   642         entries = [_filterfull(e, copy, vfsmap) for e in entries]
   652         for k, vfs, e in entries:
   643         yield None  # this release the lock on the repository
   653             for f in e.files():
       
   654                 if f.is_volatile:
       
   655                     copy(vfs.join(f.unencoded_path))
       
   656         # the first yield release the lock on the repository
       
   657         yield file_count, totalfilesize
   644         totalbytecount = 0
   658         totalbytecount = 0
   645 
   659 
   646         for src, name, ftype, data in entries:
   660         for src, vfs, e in entries:
   647             if True:
   661             for f in e.files():
   648                 vfs = vfsmap[src]
       
   649                 yield src
   662                 yield src
       
   663                 name = f.unencoded_path
   650                 yield util.uvarintencode(len(name))
   664                 yield util.uvarintencode(len(name))
   651                 if ftype == _fileappend:
   665                 actual_path = copy[vfs.join(name)]
   652                     fp = vfs(name)
   666                 fp = open(actual_path, b'rb')
   653                     size = data
   667                 size = f.file_size(vfs)
   654                 elif ftype == _filefull:
       
   655                     fp = open(data, b'rb')
       
   656                     size = util.fstat(fp).st_size
       
   657                 bytecount = 0
   668                 bytecount = 0
   658                 try:
   669                 try:
   659                     yield util.uvarintencode(size)
   670                     yield util.uvarintencode(size)
   660                     yield name
   671                     yield name
   661                     if size <= 65536:
   672                     if size <= 65536:
   766 
   777 
   767     with repo.lock():
   778     with repo.lock():
   768 
   779 
   769         repo.ui.debug(b'scanning\n')
   780         repo.ui.debug(b'scanning\n')
   770 
   781 
   771         entries, totalfilesize = _v2_walk(
   782         entries = _entries_walk(
   772             repo,
   783             repo,
   773             includes=includes,
   784             includes=includes,
   774             excludes=excludes,
   785             excludes=excludes,
   775             includeobsmarkers=includeobsmarkers,
   786             includeobsmarkers=includeobsmarkers,
   776         )
   787         )
   777 
   788 
   778         chunks = _emit2(repo, entries, totalfilesize)
   789         chunks = _emit2(repo, entries)
   779         first = next(chunks)
   790         first = next(chunks)
   780         assert first is None
   791         file_count, total_file_size = first
   781         _test_sync_point_walk_1(repo)
   792         _test_sync_point_walk_1(repo)
   782     _test_sync_point_walk_2(repo)
   793     _test_sync_point_walk_2(repo)
   783 
   794 
   784     return len(entries), totalfilesize, chunks
   795     return file_count, total_file_size, chunks
   785 
   796 
   786 
   797 
   787 def generatev3(repo, includes, excludes, includeobsmarkers):
   798 def generatev3(repo, includes, excludes, includeobsmarkers):
   788     return generatev2(repo, includes, excludes, includeobsmarkers)
   799     return generatev2(repo, includes, excludes, includeobsmarkers)
   789 
   800