comparison hgext3rd/topic/topicmap.py @ 6795:1b59ddda3242 stable

topic: further "help pytype" by not mentioning remotebranchcache on hg 4.9 Because it doesn't exist. This obviously was a real issue on Mercurial 4.9 because we were trying to directly reference a class that doesn't exist in branchmap module, it wasn't a string in some typing comment or whatever, so this code previously would not work on 4.9 at all. Oops!
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 27 Jun 2024 17:14:50 +0400
parents 68f7ba35ea83
children ed00ed185249
comparison
equal deleted inserted replaced
6794:68f7ba35ea83 6795:1b59ddda3242
178 finally: 178 finally:
179 branchmap.branchcache = current 179 branchmap.branchcache = current
180 else: 180 else:
181 oldbranchmap = util.nullcontextmanager 181 oldbranchmap = util.nullcontextmanager
182 182
183 if util.safehasattr(branchmap, 'branchcache'):
184 allbccls = (branchmap.branchcache,)
185 if util.safehasattr(branchmap, 'remotebranchcache'):
186 # hg <= 4.9 (eb7ce452e0fb)
187 allbccls = (branchmap.branchcache, branchmap.remotebranchcache)
188
183 class _topiccache(object): # combine me with branchmap.branchcache 189 class _topiccache(object): # combine me with branchmap.branchcache
184 190
185 def __init__(self, *args, **kwargs): 191 def __init__(self, *args, **kwargs):
186 with oldbranchmap(): 192 with oldbranchmap():
187 super(_topiccache, self).__init__(*args, **kwargs) 193 super(_topiccache, self).__init__(*args, **kwargs)
188 self.phaseshash = None 194 self.phaseshash = None
189 195
190 def copy(self): 196 def copy(self):
191 """return an deep copy of the branchcache object""" 197 """return an deep copy of the branchcache object"""
192 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype 198 assert isinstance(self, allbccls) # help pytype
193 entries = compat.bcentries(self) 199 entries = compat.bcentries(self)
194 args = (entries, self.tipnode, self.tiprev, self.filteredhash, 200 args = (entries, self.tipnode, self.tiprev, self.filteredhash,
195 self._closednodes) 201 self._closednodes)
196 if util.safehasattr(self, '_repo'): 202 if util.safehasattr(self, '_repo'):
197 # hg <= 5.7 (6266d19556ad) 203 # hg <= 5.7 (6266d19556ad)
216 def validfor(self, repo): 222 def validfor(self, repo):
217 """Is the cache content valid regarding a repo 223 """Is the cache content valid regarding a repo
218 224
219 - False when cached tipnode is unknown or if we detect a strip. 225 - False when cached tipnode is unknown or if we detect a strip.
220 - True when cache is up to date or a subset of current repo.""" 226 - True when cache is up to date or a subset of current repo."""
221 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype 227 assert isinstance(self, allbccls) # help pytype
222 valid = super(_topiccache, self).validfor(repo) 228 valid = super(_topiccache, self).validfor(repo)
223 if not valid: 229 if not valid:
224 return False 230 return False
225 elif not istopicfilter(repo.filtername) or self.phaseshash is None: 231 elif not istopicfilter(repo.filtername) or self.phaseshash is None:
226 # phasehash at None means this is a branchmap 232 # phasehash at None means this is a branchmap
253 def update(self, repo, revgen): 259 def update(self, repo, revgen):
254 """Given a branchhead cache, self, that may have extra nodes or be 260 """Given a branchhead cache, self, that may have extra nodes or be
255 missing heads, and a generator of nodes that are strictly a superset of 261 missing heads, and a generator of nodes that are strictly a superset of
256 heads missing, this function updates self to be correct. 262 heads missing, this function updates self to be correct.
257 """ 263 """
258 assert isinstance(self, (branchmap.branchcache, branchmap.remotebranchcache)) # help pytype 264 assert isinstance(self, allbccls) # help pytype
259 if not istopicfilter(repo.filtername): 265 if not istopicfilter(repo.filtername):
260 return super(_topiccache, self).update(repo, revgen) 266 return super(_topiccache, self).update(repo, revgen)
261 267
262 # See topic.discovery._headssummary(), where repo.unfiltered gets 268 # See topic.discovery._headssummary(), where repo.unfiltered gets
263 # overridden to return .filtered('unfiltered-topic'). revbranchcache 269 # overridden to return .filtered('unfiltered-topic'). revbranchcache