revlog: adapt the `reading` check for `unionrepo`
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 25 Sep 2023 12:14:38 +0200
changeset 51013 93a44c1ba0c6
parent 51012 3470a39fb66b
child 51014 ed65e97db7bc
revlog: adapt the `reading` check for `unionrepo` We cannot just rely on the length check for the `unionrepo` as the local revlog might be empty while the other revlog contains data. In addition, we need to also open the second revlog for reading when needed.
mercurial/unionrepo.py
--- a/mercurial/unionrepo.py	Mon Sep 25 12:13:38 2023 +0200
+++ b/mercurial/unionrepo.py	Mon Sep 25 12:14:38 2023 +0200
@@ -11,6 +11,8 @@
 allowing operations like diff and log with revsets.
 """
 
+import contextlib
+
 
 from .i18n import _
 
@@ -112,6 +114,19 @@
             self.bundlerevs.add(n)
             n += 1
 
+    @contextlib.contextmanager
+    def reading(self):
+        if 0 <= len(self.bundlerevs) < len(self.index):
+            read_1 = super().reading
+        else:
+            read_1 = util.nullcontextmanager
+        if 0 < len(self.bundlerevs):
+            read_2 = self.revlog2.reading
+        else:
+            read_2 = util.nullcontextmanager
+        with read_1(), read_2():
+            yield
+
     def _chunk(self, rev, df=None):
         if rev <= self.repotiprev:
             return revlog.revlog._chunk(self, rev)