changeset 52017:0ad269e24075

stream: open volatile file through the manager To do more subtle things, we need more control.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 01 Oct 2024 15:55:29 +0200
parents e308439339e2
children 4801fde72cc2
files mercurial/store.py mercurial/streamclone.py
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/store.py	Mon Oct 14 15:11:49 2024 +0200
+++ b/mercurial/store.py	Tue Oct 01 15:55:29 2024 +0200
@@ -485,8 +485,8 @@
         size = self.file_size(None)
 
         def get_stream():
-            actual_path = volatiles[vfs.join(self.unencoded_path)]
-            with open(actual_path, 'rb') as fp:
+            path = vfs.join(self.unencoded_path)
+            with volatiles.open(path) as fp:
                 yield None  # ready to stream
                 if size <= 65536:
                     yield fp.read(size)
--- a/mercurial/streamclone.py	Mon Oct 14 15:11:49 2024 +0200
+++ b/mercurial/streamclone.py	Tue Oct 01 15:55:29 2024 +0200
@@ -608,6 +608,12 @@
         unmodified."""
         return self._copies.get(src, src)
 
+    @contextlib.contextmanager
+    def open(self, src):
+        actual_path = self._copies.get(src, src)
+        with open(actual_path, 'rb') as fp:
+            yield fp
+
     def __exit__(self, *args, **kwars):
         """discard all backups"""
         for tmp in self._copies.values():