comparison hgext3rd/topic/topicmap.py @ 6824:417f775d3eee

topic: we checked that branchmap.branchcache exists, let pytype know this
author Anton Shestakov <av6@dwimlabs.net>
date Fri, 12 Jul 2024 15:44:12 +0400
parents ed00ed185249
children
comparison
equal deleted inserted replaced
6823:47c7b5ccabd0 6824:417f775d3eee
131 class remotetopiccache(_TopicCacheV2, branchmap.remotebranchcache): 131 class remotetopiccache(_TopicCacheV2, branchmap.remotebranchcache):
132 pass 132 pass
133 branchmap.remotebranchcache = remotetopiccache 133 branchmap.remotebranchcache = remotetopiccache
134 else: 134 else:
135 # hg <= 6.7 (ec640dc9cebd) 135 # hg <= 6.7 (ec640dc9cebd)
136 assert hasattr(branchmap, 'branchcache') # help pytype
137
136 class topiccache(_topiccache, branchmap.branchcache): 138 class topiccache(_topiccache, branchmap.branchcache):
137 pass 139 pass
138 branchmap.branchcache = topiccache 140 branchmap.branchcache = topiccache
139 141
140 class remotetopiccache(_topiccache, branchmap.remotebranchcache): 142 class remotetopiccache(_topiccache, branchmap.remotebranchcache):
160 super(_topiccache, self).__init__(*args, **kwargs) 162 super(_topiccache, self).__init__(*args, **kwargs)
161 self.phaseshash = None 163 self.phaseshash = None
162 164
163 def copy(self): 165 def copy(self):
164 """return an deep copy of the branchcache object""" 166 """return an deep copy of the branchcache object"""
167 assert hasattr(branchmap, 'branchcache') # help pytype
165 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype 168 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype
166 args = (self._entries, self.tipnode, self.tiprev, self.filteredhash, 169 args = (self._entries, self.tipnode, self.tiprev, self.filteredhash,
167 self._closednodes) 170 self._closednodes)
168 if util.safehasattr(self, '_repo'): 171 if util.safehasattr(self, '_repo'):
169 # hg <= 5.7 (6266d19556ad) 172 # hg <= 5.7 (6266d19556ad)
174 177
175 def load(self, repo, lineiter): 178 def load(self, repo, lineiter):
176 """call branchmap.load(), and then transform branch names to be in the 179 """call branchmap.load(), and then transform branch names to be in the
177 new "//" format 180 new "//" format
178 """ 181 """
182 assert hasattr(branchmap, 'branchcache') # help pytype
179 assert isinstance(self, branchmap.branchcache) # help pytype 183 assert isinstance(self, branchmap.branchcache) # help pytype
180 super(_topiccache, self).load(repo, lineiter) 184 super(_topiccache, self).load(repo, lineiter)
181 185
182 for branch in tuple(self._entries): 186 for branch in tuple(self._entries):
183 formatted = common.formatfqbn(branch=branch) 187 formatted = common.formatfqbn(branch=branch)
187 def validfor(self, repo): 191 def validfor(self, repo):
188 """Is the cache content valid regarding a repo 192 """Is the cache content valid regarding a repo
189 193
190 - False when cached tipnode is unknown or if we detect a strip. 194 - False when cached tipnode is unknown or if we detect a strip.
191 - True when cache is up to date or a subset of current repo.""" 195 - True when cache is up to date or a subset of current repo."""
196 assert hasattr(branchmap, 'branchcache') # help pytype
192 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype 197 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype
193 valid = super(_topiccache, self).validfor(repo) 198 valid = super(_topiccache, self).validfor(repo)
194 if not valid: 199 if not valid:
195 return False 200 return False
196 elif not istopicfilter(repo.filtername) or self.phaseshash is None: 201 elif not istopicfilter(repo.filtername) or self.phaseshash is None:
223 def update(self, repo, revgen): 228 def update(self, repo, revgen):
224 """Given a branchhead cache, self, that may have extra nodes or be 229 """Given a branchhead cache, self, that may have extra nodes or be
225 missing heads, and a generator of nodes that are strictly a superset of 230 missing heads, and a generator of nodes that are strictly a superset of
226 heads missing, this function updates self to be correct. 231 heads missing, this function updates self to be correct.
227 """ 232 """
233 assert hasattr(branchmap, 'branchcache') # help pytype
228 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype 234 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype
229 if not istopicfilter(repo.filtername): 235 if not istopicfilter(repo.filtername):
230 return super(_topiccache, self).update(repo, revgen) 236 return super(_topiccache, self).update(repo, revgen)
231 237
232 # See topic.discovery._headssummary(), where repo.unfiltered gets 238 # See topic.discovery._headssummary(), where repo.unfiltered gets
282 """write cache to disk if it's not topic-only, but first transform 288 """write cache to disk if it's not topic-only, but first transform
283 cache keys from branches in "//" format into bare branch names 289 cache keys from branches in "//" format into bare branch names
284 """ 290 """
285 # we expect mutable set to be small enough to be that computing it all 291 # we expect mutable set to be small enough to be that computing it all
286 # the time will be fast enough 292 # the time will be fast enough
293 assert isinstance(self, branchmap.BranchCacheV2) # help pytype
287 if not istopicfilter(repo.filtername): 294 if not istopicfilter(repo.filtername):
288 entries = self._entries.copy() 295 entries = self._entries.copy()
289 296
290 for formatted in tuple(entries): 297 for formatted in tuple(entries):
291 branch, tns, topic = common.parsefqbn(formatted) 298 branch, tns, topic = common.parsefqbn(formatted)