comparison mercurial/vfs.py @ 52927:b6f24a92b399

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 30 Nov 2024 02:24:22 +0100
parents 6ee3c401882b
children 5b8f6e198a6e
comparison
equal deleted inserted replaced
52926:34fa51c25112 52927:b6f24a92b399
554 notindexed: bool = False, 554 notindexed: bool = False,
555 backgroundclose: bool = False, 555 backgroundclose: bool = False,
556 checkambig: bool = False, 556 checkambig: bool = False,
557 auditpath: bool = True, 557 auditpath: bool = True,
558 makeparentdirs: bool = True, 558 makeparentdirs: bool = True,
559 buffering: int = -1,
559 ) -> Any: # TODO: should be BinaryIO if util.atomictempfile can be coersed 560 ) -> Any: # TODO: should be BinaryIO if util.atomictempfile can be coersed
560 """Open ``path`` file, which is relative to vfs root. 561 """Open ``path`` file, which is relative to vfs root.
561 562
562 By default, parent directories are created as needed. Newly created 563 By default, parent directories are created as needed. Newly created
563 directories are marked as "not to be indexed by the content indexing 564 directories are marked as "not to be indexed by the content indexing
624 if nlink > 0: 625 if nlink > 0:
625 if self._trustnlink is None: 626 if self._trustnlink is None:
626 self._trustnlink = nlink > 1 or util.checknlink(f) 627 self._trustnlink = nlink > 1 or util.checknlink(f)
627 if nlink > 1 or not self._trustnlink: 628 if nlink > 1 or not self._trustnlink:
628 util.rename(util.mktempcopy(f), f) 629 util.rename(util.mktempcopy(f), f)
629 fp = util.posixfile(f, mode) 630 fp = util.posixfile(f, mode, buffering=buffering)
630 if nlink == 0: 631 if nlink == 0:
631 self._fixfilemode(f) 632 self._fixfilemode(f)
632 633
633 if checkambig: 634 if checkambig:
634 if mode in (b'r', b'rb'): 635 if mode in (b'r', b'rb'):