changeset 51011: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 c690d2cc7f36
children 3470a39fb66b
files mercurial/revlog.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Sep 25 11:59:38 2023 +0200
+++ b/mercurial/revlog.py	Mon Sep 25 12:07:25 2023 +0200
@@ -2282,9 +2282,12 @@
     @contextlib.contextmanager
     def reading(self):
         """Context manager that keeps data and sidedata files open for reading"""
-        with self._segmentfile.reading():
-            with self._segmentfile_sidedata.reading():
-                yield
+        if len(self.index) == 0:
+            yield  # nothing to be read
+        else:
+            with self._segmentfile.reading():
+                with self._segmentfile_sidedata.reading():
+                    yield
 
     @contextlib.contextmanager
     def _writing(self, transaction):