changeset 50549:06d580b8f432

stream-clone: introduce a _entries_walk That function insert itself between the store and `_v2_walk`. It only deals with StoreEntry unlike `_v2_walk` that deal with actual file. A share of the `_v2_walk` logic will be moved in this new `_entry_walk` function. Having this function will help us to implement a new "v3" version of the protocol that will be more entry centric.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 21 May 2023 03:10:59 +0200
parents 0925eaf09c8b
children 43ed1f12b00a
files mercurial/streamclone.py
diffstat 1 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/streamclone.py	Sun May 21 02:29:33 2023 +0200
+++ b/mercurial/streamclone.py	Sun May 21 03:10:59 2023 +0200
@@ -659,6 +659,30 @@
     """a function for synchronisation during tests"""
 
 
+def _entries_walk(repo, includes, excludes, includeobsmarkers):
+    """emit a seris of files information useful to clone a repo
+
+    return (vfs-key, entry) iterator
+
+    Where `entry` is StoreEntry. (used even for cache entries)
+    """
+    assert repo._currentlock(repo._lockref) is not None
+
+    matcher = None
+    if includes or excludes:
+        matcher = narrowspec.match(repo.root, includes, excludes)
+
+    phase = not repo.publishing()
+    entries = _walkstreamfiles(
+        repo,
+        matcher,
+        phase=phase,
+        obsolescence=includeobsmarkers,
+    )
+    for entry in entries:
+        yield (_srcstore, entry)
+
+
 def _v2_walk(repo, includes, excludes, includeobsmarkers):
     """emit a seris of files information useful to clone a repo
 
@@ -675,22 +699,17 @@
     files = []
     totalfilesize = 0
 
-    matcher = None
-    if includes or excludes:
-        matcher = narrowspec.match(repo.root, includes, excludes)
-
-    phase = not repo.publishing()
-    entries = _walkstreamfiles(
-        repo, matcher, phase=phase, obsolescence=includeobsmarkers
-    )
-    for entry in entries:
+    vfsmap = _makemap(repo)
+    entries = _entries_walk(repo, includes, excludes, includeobsmarkers)
+    for vfs_key, entry in entries:
+        vfs = vfsmap[vfs_key]
         for f in entry.files():
-            file_size = f.file_size(repo.store.vfs)
+            file_size = f.file_size(vfs)
             if file_size:
                 ft = _fileappend
                 if f.is_volatile:
                     ft = _filefull
-                files.append((_srcstore, f.unencoded_path, ft, file_size))
+                files.append((vfs_key, f.unencoded_path, ft, file_size))
                 totalfilesize += file_size
     for name in cacheutil.cachetocopy(repo):
         if repo.cachevfs.exists(name):