changeset 51013:93a44c1ba0c6

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 25 Sep 2023 12:14:38 +0200
parents 3470a39fb66b
children ed65e97db7bc
files mercurial/unionrepo.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)