vfs: add a "buffering" argument to vfs mirroring the Python one
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 30 Nov 2024 02:24:22 +0100
changeset 52927 b6f24a92b399
parent 52926 34fa51c25112
child 52928 7fc882f7fada
vfs: add a "buffering" argument to vfs mirroring the Python one This option let you control python buffering behavior on open file. We will use it to speed up the writing of data on disk during stream clone.
mercurial/vfs.py
--- a/mercurial/vfs.py	Fri Nov 29 22:22:54 2024 +0100
+++ b/mercurial/vfs.py	Sat Nov 30 02:24:22 2024 +0100
@@ -556,6 +556,7 @@
         checkambig: bool = False,
         auditpath: bool = True,
         makeparentdirs: bool = True,
+        buffering: int = -1,
     ) -> Any:  # TODO: should be BinaryIO if util.atomictempfile can be coersed
         """Open ``path`` file, which is relative to vfs root.
 
@@ -626,7 +627,7 @@
                         self._trustnlink = nlink > 1 or util.checknlink(f)
                     if nlink > 1 or not self._trustnlink:
                         util.rename(util.mktempcopy(f), f)
-        fp = util.posixfile(f, mode)
+        fp = util.posixfile(f, mode, buffering=buffering)
         if nlink == 0:
             self._fixfilemode(f)