comparison mercurial/revlogutils/randomaccessfile.py @ 51103:d83d788590a8

changelog-delay: move the delay/divert logic inside the (inner) revlog Instead of hacking throught the vfs/opener, we implement the delay/divert logic inside the `_InnerRevlog` and `randomaccessfile` object. This will allow to an alternative implementation of the `_InnerRevlog` that does not need to use Python details. As a result, the new implementation can use the transaction less agressively and avoid some extra output since no data had been written yet. That seems like a good side effect.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 24 Oct 2023 11:08:49 +0200
parents 222b89224397
children a93e52f0b6ff
comparison
equal deleted inserted replaced
51102:af96fbb8f739 51103:d83d788590a8
114 self._cached_chunk = b'' 114 self._cached_chunk = b''
115 self._cached_chunk_position = 0 # Offset from the start of the file 115 self._cached_chunk_position = 0 # Offset from the start of the file
116 if initial_cache: 116 if initial_cache:
117 self._cached_chunk_position, self._cached_chunk = initial_cache 117 self._cached_chunk_position, self._cached_chunk = initial_cache
118 118
119 self._delay_buffer = None
120
119 def clear_cache(self): 121 def clear_cache(self):
120 self._cached_chunk = b'' 122 self._cached_chunk = b''
121 self._cached_chunk_position = 0 123 self._cached_chunk_position = 0
122 124
123 @property 125 @property
129 self.reading_handle is not None or self.writing_handle is not None 131 self.reading_handle is not None or self.writing_handle is not None
130 ) 132 )
131 133
132 def _open(self, mode=b'r'): 134 def _open(self, mode=b'r'):
133 """Return a file object""" 135 """Return a file object"""
134 return self.opener(self.filename, mode=mode) 136 if self._delay_buffer is None:
137 return self.opener(self.filename, mode=mode)
138 else:
139 return appender(
140 self.opener, self.filename, mode, self._delay_buffer
141 )
135 142
136 @contextlib.contextmanager 143 @contextlib.contextmanager
137 def _read_handle(self): 144 def _read_handle(self):
138 """File object suitable for reading data""" 145 """File object suitable for reading data"""
139 # Use a file handle being actively used for writes, if available. 146 # Use a file handle being actively used for writes, if available.