revlog: make `reading` not crash on empty repository
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 25 Sep 2023 12:07:25 +0200
changeset 51011 9461a0b74596
parent 51010 c690d2cc7f36
child 51012 3470a39fb66b
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.
mercurial/revlog.py
--- 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):