Mercurial > public > mercurial-scm > hg
comparison mercurial/unionrepo.py @ 51010: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 | 18c8c18993f0 |
children | 8520db304f01 |
comparison
equal
deleted
inserted
replaced
51009:3470a39fb66b | 51010:93a44c1ba0c6 |
---|---|
8 # GNU General Public License version 2 or any later version. | 8 # GNU General Public License version 2 or any later version. |
9 | 9 |
10 """Repository class for "in-memory pull" of one local repository to another, | 10 """Repository class for "in-memory pull" of one local repository to another, |
11 allowing operations like diff and log with revsets. | 11 allowing operations like diff and log with revsets. |
12 """ | 12 """ |
13 | |
14 import contextlib | |
13 | 15 |
14 | 16 |
15 from .i18n import _ | 17 from .i18n import _ |
16 | 18 |
17 from . import ( | 19 from . import ( |
110 ) | 112 ) |
111 self.index.append(e) | 113 self.index.append(e) |
112 self.bundlerevs.add(n) | 114 self.bundlerevs.add(n) |
113 n += 1 | 115 n += 1 |
114 | 116 |
117 @contextlib.contextmanager | |
118 def reading(self): | |
119 if 0 <= len(self.bundlerevs) < len(self.index): | |
120 read_1 = super().reading | |
121 else: | |
122 read_1 = util.nullcontextmanager | |
123 if 0 < len(self.bundlerevs): | |
124 read_2 = self.revlog2.reading | |
125 else: | |
126 read_2 = util.nullcontextmanager | |
127 with read_1(), read_2(): | |
128 yield | |
129 | |
115 def _chunk(self, rev, df=None): | 130 def _chunk(self, rev, df=None): |
116 if rev <= self.repotiprev: | 131 if rev <= self.repotiprev: |
117 return revlog.revlog._chunk(self, rev) | 132 return revlog.revlog._chunk(self, rev) |
118 return self.revlog2._chunk(self.node(rev)) | 133 return self.revlog2._chunk(self.node(rev)) |
119 | 134 |