Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revlogutils/randomaccessfile.py @ 51110: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 |
line wrap: on
line diff
--- a/mercurial/revlogutils/randomaccessfile.py Thu Oct 26 05:37:37 2023 +0200 +++ b/mercurial/revlogutils/randomaccessfile.py Tue Oct 24 11:08:49 2023 +0200 @@ -116,6 +116,8 @@ if initial_cache: self._cached_chunk_position, self._cached_chunk = initial_cache + self._delay_buffer = None + def clear_cache(self): self._cached_chunk = b'' self._cached_chunk_position = 0 @@ -131,7 +133,12 @@ def _open(self, mode=b'r'): """Return a file object""" - return self.opener(self.filename, mode=mode) + if self._delay_buffer is None: + return self.opener(self.filename, mode=mode) + else: + return appender( + self.opener, self.filename, mode, self._delay_buffer + ) @contextlib.contextmanager def _read_handle(self):