changeset 52922:70306aefa52b

stream-clone-v2: extract the file writing code in a function Same rational as for extracting the parsing code.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 20 Jan 2025 12:32:37 +0100
parents 3ee343dd3abf
children 307c4a0b91a0
files mercurial/streamclone.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/streamclone.py	Mon Jan 20 12:16:54 2025 +0100
+++ b/mercurial/streamclone.py	Mon Jan 20 12:32:37 2025 +0100
@@ -1110,11 +1110,7 @@
                     progress,
                     report,
                 )
-                for src, name, chunks in files:
-                    vfs = vfsmap[src]
-                    with vfs(name, b'w') as ofp:
-                        for c in chunks:
-                            ofp.write(c)
+                _write_files(vfsmap, files)
 
             # force @filecache properties to be reloaded from
             # streamclone-ed file at next access
@@ -1182,6 +1178,15 @@
         yield (src, name, _v2_file_chunk(fp, datalen, progress, report))
 
 
+def _write_files(vfsmap, info: Iterable[FileInfoT]):
+    """write files from parsed data"""
+    for src, name, data in info:
+        vfs = vfsmap[src]
+        with vfs(name, b'w') as ofp:
+            for chunk in data:
+                ofp.write(chunk)
+
+
 def consumev3(repo, fp) -> None:
     """Apply the contents from a version 3 streaming clone.