Mercurial > hg
changeset 51102:594f912818ab
changelog-delay: adds some check around delaying and diverting write
Theses assert shows we never call delay or divert if the revlog hold file handle
on the revlog's file.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 20 Oct 2023 12:13:33 +0200 |
parents | 045b5f745f93 |
children | 222b89224397 |
files | mercurial/changelog.py mercurial/revlog.py mercurial/revlogutils/randomaccessfile.py |
diffstat | 3 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Wed Oct 25 23:14:20 2023 +0200 +++ b/mercurial/changelog.py Fri Oct 20 12:13:33 2023 +0200 @@ -448,6 +448,7 @@ def delayupdate(self, tr): """delay visibility of index updates to other readers""" + assert not self._inner.is_open if self._docket is None and not self._delayed: if len(self) == 0: self._divert = True @@ -468,6 +469,7 @@ def _finalize(self, tr): """finalize index updates""" + assert not self._inner.is_open self._delayed = False self.opener = self._realopener self._inner.opener = self.opener @@ -494,6 +496,7 @@ def _writepending(self, tr): """create a file containing the unfinalized state for pretxnchangegroup""" + assert not self._inner.is_open if self._docket: return self._docket.write(tr, pending=True) if self._delaybuf:
--- a/mercurial/revlog.py Wed Oct 25 23:14:20 2023 +0200 +++ b/mercurial/revlog.py Fri Oct 20 12:13:33 2023 +0200 @@ -620,6 +620,13 @@ """True is a writing context is open""" return self._writinghandles is not None + @property + def is_open(self): + """True if any file handle is being held + + Used for assert and debug in the python code""" + return self._segmentfile.is_open or self._segmentfile_sidedata.is_open + @contextlib.contextmanager def writing(self, transaction, data_end=None, sidedata_end=None): """Open the revlog files for writing
--- a/mercurial/revlogutils/randomaccessfile.py Wed Oct 25 23:14:20 2023 +0200 +++ b/mercurial/revlogutils/randomaccessfile.py Fri Oct 20 12:13:33 2023 +0200 @@ -50,6 +50,15 @@ self._cached_chunk = b'' self._cached_chunk_position = 0 + @property + def is_open(self): + """True if any file handle is being held + + Used for assert and debug in the python code""" + return ( + self.reading_handle is not None or self.writing_handle is not None + ) + def _open(self, mode=b'r'): """Return a file object""" return self.opener(self.filename, mode=mode)