mercurial/streamclone.py
changeset 47444 2f4ca4807033
parent 46989 aed6ceaad6d7
child 47447 377d8fc20e34
equal deleted inserted replaced
47443:9ab54aa56982 47444:2f4ca4807033
   601 
   601 
   602 def _test_sync_point_walk_2(repo):
   602 def _test_sync_point_walk_2(repo):
   603     """a function for synchronisation during tests"""
   603     """a function for synchronisation during tests"""
   604 
   604 
   605 
   605 
       
   606 def _v2_walk(repo, includes, excludes, includeobsmarkers):
       
   607     """emit a seris of files information useful to clone a repo
       
   608 
       
   609     return (entries, totalfilesize)
       
   610 
       
   611     entries is a list of tuple (vfs-key, file-path, file-type, size)
       
   612 
       
   613     - `vfs-key`: is a key to the right vfs to write the file (see _makemap)
       
   614     - `name`: file path of the file to copy (to be feed to the vfss)
       
   615     - `file-type`: do this file need to be copied with the source lock ?
       
   616     - `size`: the size of the file (or None)
       
   617     """
       
   618     assert repo._currentlock(repo._lockref) is not None
       
   619     entries = []
       
   620     totalfilesize = 0
       
   621 
       
   622     matcher = None
       
   623     if includes or excludes:
       
   624         matcher = narrowspec.match(repo.root, includes, excludes)
       
   625 
       
   626     for rl_type, name, ename, size in _walkstreamfiles(repo, matcher):
       
   627         if size:
       
   628             ft = _fileappend
       
   629             if rl_type & store.FILEFLAGS_VOLATILE:
       
   630                 ft = _filefull
       
   631             entries.append((_srcstore, name, ft, size))
       
   632             totalfilesize += size
       
   633     for name in _walkstreamfullstorefiles(repo):
       
   634         if repo.svfs.exists(name):
       
   635             totalfilesize += repo.svfs.lstat(name).st_size
       
   636             entries.append((_srcstore, name, _filefull, None))
       
   637     if includeobsmarkers and repo.svfs.exists(b'obsstore'):
       
   638         totalfilesize += repo.svfs.lstat(b'obsstore').st_size
       
   639         entries.append((_srcstore, b'obsstore', _filefull, None))
       
   640     for name in cacheutil.cachetocopy(repo):
       
   641         if repo.cachevfs.exists(name):
       
   642             totalfilesize += repo.cachevfs.lstat(name).st_size
       
   643             entries.append((_srccache, name, _filefull, None))
       
   644     return entries, totalfilesize
       
   645 
       
   646 
   606 def generatev2(repo, includes, excludes, includeobsmarkers):
   647 def generatev2(repo, includes, excludes, includeobsmarkers):
   607     """Emit content for version 2 of a streaming clone.
   648     """Emit content for version 2 of a streaming clone.
   608 
   649 
   609     the data stream consists the following entries:
   650     the data stream consists the following entries:
   610     1) A char representing the file destination (eg: store or cache)
   651     1) A char representing the file destination (eg: store or cache)
   616     Returns a 3-tuple of (file count, file size, data iterator).
   657     Returns a 3-tuple of (file count, file size, data iterator).
   617     """
   658     """
   618 
   659 
   619     with repo.lock():
   660     with repo.lock():
   620 
   661 
   621         entries = []
       
   622         totalfilesize = 0
       
   623 
       
   624         matcher = None
       
   625         if includes or excludes:
       
   626             matcher = narrowspec.match(repo.root, includes, excludes)
       
   627 
       
   628         repo.ui.debug(b'scanning\n')
   662         repo.ui.debug(b'scanning\n')
   629         for rl_type, name, ename, size in _walkstreamfiles(repo, matcher):
   663 
   630             if size:
   664         entries, totalfilesize = _v2_walk(
   631                 ft = _fileappend
   665             repo,
   632                 if rl_type & store.FILEFLAGS_VOLATILE:
   666             includes=includes,
   633                     ft = _filefull
   667             excludes=excludes,
   634                 entries.append((_srcstore, name, ft, size))
   668             includeobsmarkers=includeobsmarkers,
   635                 totalfilesize += size
   669         )
   636         for name in _walkstreamfullstorefiles(repo):
       
   637             if repo.svfs.exists(name):
       
   638                 totalfilesize += repo.svfs.lstat(name).st_size
       
   639                 entries.append((_srcstore, name, _filefull, None))
       
   640         if includeobsmarkers and repo.svfs.exists(b'obsstore'):
       
   641             totalfilesize += repo.svfs.lstat(b'obsstore').st_size
       
   642             entries.append((_srcstore, b'obsstore', _filefull, None))
       
   643         for name in cacheutil.cachetocopy(repo):
       
   644             if repo.cachevfs.exists(name):
       
   645                 totalfilesize += repo.cachevfs.lstat(name).st_size
       
   646                 entries.append((_srccache, name, _filefull, None))
       
   647 
   670 
   648         chunks = _emit2(repo, entries, totalfilesize)
   671         chunks = _emit2(repo, entries, totalfilesize)
   649         first = next(chunks)
   672         first = next(chunks)
   650         assert first is None
   673         assert first is None
   651         _test_sync_point_walk_1(repo)
   674         _test_sync_point_walk_1(repo)