comparison mercurial/unionrepo.py @ 51871:8315175f678d

unionrepo: fix mismatches with revlog classes This is a subset of cfd30df0f8e4, applied to `unionrepository`. There are none of the `write()` method overrides here, like `bundlerepository`. With these changes, pytype flags the `unionrevlog` constructor: File "/mnt/c/Users/Matt/hg/mercurial/unionrepo.py", line 55, in __init__: No attribute '_revlog' on mercurial.changelog.changelog [attribute-error] Called from (traceback): line 207, in __init__ File "/mnt/c/Users/Matt/hg/mercurial/unionrepo.py", line 55, in __init__: No attribute '_revlog' on mercurial.revlog.revlog [attribute-error] Called from (traceback): line 232, in __init__ But it turns out that both `changelog.changelog` and `revlog.revlog` do have a `target` attribute, so they wouldn't trip over this. It seems weird that the second caller to be flagged is passing the private `_revlog`, but maybe that's how it needs to be.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 19 Sep 2024 18:48:07 -0400
parents 1b17309cdaab
children 4675ab746a02
comparison
equal deleted inserted replaced
51870:1b17309cdaab 51871:8315175f678d
37 constants as revlog_constants, 37 constants as revlog_constants,
38 ) 38 )
39 39
40 40
41 class unionrevlog(revlog.revlog): 41 class unionrevlog(revlog.revlog):
42 def __init__(self, opener, radix, revlog2, linkmapper): 42 def __init__(self, opener: typing.Any, radix, revlog2, linkmapper):
43 # TODO: figure out real type of opener
44 #
43 # How it works: 45 # How it works:
44 # To retrieve a revision, we just need to know the node id so we can 46 # To retrieve a revision, we just need to know the node id so we can
45 # look it up in revlog2. 47 # look it up in revlog2.
46 # 48 #
47 # To differentiate a rev in the second revlog from a rev in the revlog, 49 # To differentiate a rev in the second revlog from a rev in the revlog,
48 # we check revision against repotiprev. 50 # we check revision against repotiprev.
49 opener = vfsmod.readonlyvfs(opener) 51 opener = vfsmod.readonlyvfs(opener)
50 target = getattr(revlog2, 'target', None) 52 target = getattr(revlog2, 'target', None)
51 if target is None: 53 if target is None:
54 # Help pytype- changelog and revlog are not possible here because
55 # they both have a 'target' attr.
56 assert not isinstance(revlog2, (changelog.changelog, revlog.revlog))
57
52 # a revlog wrapper, eg: the manifestlog that is not an actual revlog 58 # a revlog wrapper, eg: the manifestlog that is not an actual revlog
53 target = revlog2._revlog.target 59 target = revlog2._revlog.target
54 revlog.revlog.__init__(self, opener, target=target, radix=radix) 60 revlog.revlog.__init__(self, opener, target=target, radix=radix)
55 self.revlog2 = revlog2 61 self.revlog2 = revlog2
56 62
129 with read_1(), read_2(): 135 with read_1(), read_2():
130 yield 136 yield
131 137
132 def _chunk(self, rev): 138 def _chunk(self, rev):
133 if rev <= self.repotiprev: 139 if rev <= self.repotiprev:
134 return revlog.revlog._chunk(self, rev) 140 return super(unionrevlog, self)._inner._chunk(rev)
135 return self.revlog2._chunk(self.node(rev)) 141 return self.revlog2._chunk(self.node(rev))
136 142
137 def revdiff(self, rev1, rev2): 143 def revdiff(self, rev1, rev2):
138 """return or calculate a delta between two revisions""" 144 """return or calculate a delta between two revisions"""
139 if rev1 > self.repotiprev and rev2 > self.repotiprev: 145 if rev1 > self.repotiprev and rev2 > self.repotiprev: