comparison mercurial/revlog.py @ 51008:9461a0b74596

revlog: make `reading` not crash on empty repository If the revlog is empty, the file might not exist and the open will fails. This is not great, but that details or this is now contained in the revlog itself.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 25 Sep 2023 12:07:25 +0200
parents ccddd2f54013
children aed91a4421b8
comparison
equal deleted inserted replaced
51007:c690d2cc7f36 51008:9461a0b74596
2280 """called when trying to add a node already stored.""" 2280 """called when trying to add a node already stored."""
2281 2281
2282 @contextlib.contextmanager 2282 @contextlib.contextmanager
2283 def reading(self): 2283 def reading(self):
2284 """Context manager that keeps data and sidedata files open for reading""" 2284 """Context manager that keeps data and sidedata files open for reading"""
2285 with self._segmentfile.reading(): 2285 if len(self.index) == 0:
2286 with self._segmentfile_sidedata.reading(): 2286 yield # nothing to be read
2287 yield 2287 else:
2288 with self._segmentfile.reading():
2289 with self._segmentfile_sidedata.reading():
2290 yield
2288 2291
2289 @contextlib.contextmanager 2292 @contextlib.contextmanager
2290 def _writing(self, transaction): 2293 def _writing(self, transaction):
2291 if self._trypending: 2294 if self._trypending:
2292 msg = b'try to write in a `trypending` revlog: %s' 2295 msg = b'try to write in a `trypending` revlog: %s'