comparison mercurial/localrepo.py @ 18189:b9026ba002f6

branchmap: enable caching for filtered version too The `_branchcache` attribute is turned into a dictionary. Key are filter name and value is a `branchcache` object. Unfiltered version is cached as `None` filter. The attribute is renamed to `_branchcaches` to avoid confusion with the previous one. Both old and new contents are dictionary even if their contents are different. I prefer possible extension code to crash right away instead of just messing the wrong dictionary. As all different caches work isolated to each other, this code keeps the previous behavior of using the unfiltered cache we nothing is filtered. This is a cheap way to have cache collaborate and nullify potential impact in the default case.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Mon, 24 Dec 2012 03:21:15 +0100
parents d336f53cb2e3
children c565761dde6a
comparison
equal deleted inserted replaced
18188:46ed5226503a 18189:b9026ba002f6
227 self._applyrequirements(requirements) 227 self._applyrequirements(requirements)
228 if create: 228 if create:
229 self._writerequirements() 229 self._writerequirements()
230 230
231 231
232 self._branchcache = None 232 self._branchcaches = {}
233 self.filterpats = {} 233 self.filterpats = {}
234 self._datafilters = {} 234 self._datafilters = {}
235 self._transref = self._lockref = self._wlockref = None 235 self._transref = self._lockref = self._wlockref = None
236 236
237 # A cache for various files under .hg/ that tracks file changes, 237 # A cache for various files under .hg/ that tracks file changes,
662 cl = self.changelog 662 cl = self.changelog
663 return cl.rev(cl.tip()) 663 return cl.rev(cl.tip())
664 664
665 def branchmap(self): 665 def branchmap(self):
666 '''returns a dictionary {branch: [branchheads]}''' 666 '''returns a dictionary {branch: [branchheads]}'''
667 if self.changelog.filteredrevs: 667 if self.filtername and not self.changelog.filteredrevs:
668 # some changeset are excluded we can't use the cache 668 return self.unfiltered().branchmap()
669 bmap = branchmap.branchcache() 669 branchmap.updatecache(self)
670 bmap.update(self, (self[r] for r in self)) 670 return self._branchcaches[self.filtername]
671 return bmap
672 else:
673 branchmap.updatecache(self)
674 return self._branchcache
675 671
676 672
677 def _branchtip(self, heads): 673 def _branchtip(self, heads):
678 '''return the tipmost branch head in heads''' 674 '''return the tipmost branch head in heads'''
679 tip = heads[-1] 675 tip = heads[-1]
976 972
977 if '_tagscache' in vars(self): 973 if '_tagscache' in vars(self):
978 # can't use delattr on proxy 974 # can't use delattr on proxy
979 del self.__dict__['_tagscache'] 975 del self.__dict__['_tagscache']
980 976
981 self.unfiltered()._branchcache = None # in UTF-8 977 self.unfiltered()._branchcaches.clear()
982 self.invalidatevolatilesets() 978 self.invalidatevolatilesets()
983 979
984 def invalidatevolatilesets(self): 980 def invalidatevolatilesets(self):
985 self.filteredrevcache.clear() 981 self.filteredrevcache.clear()
986 obsolete.clearobscaches(self) 982 obsolete.clearobscaches(self)
1435 # it, Otherwise, since nodes were destroyed, the cache is stale and this 1431 # it, Otherwise, since nodes were destroyed, the cache is stale and this
1436 # will be caught the next time it is read. 1432 # will be caught the next time it is read.
1437 if newheadnodes: 1433 if newheadnodes:
1438 ctxgen = (self[node] for node in newheadnodes 1434 ctxgen = (self[node] for node in newheadnodes
1439 if self.changelog.hasnode(node)) 1435 if self.changelog.hasnode(node))
1440 cache = self._branchcache 1436 cache = self._branchcaches[None]
1441 cache.update(self, ctxgen) 1437 cache.update(self, ctxgen)
1442 cache.write(self) 1438 cache.write(self)
1443 1439
1444 # Ensure the persistent tag cache is updated. Doing it now 1440 # Ensure the persistent tag cache is updated. Doing it now
1445 # means that the tag cache only has to worry about destroyed 1441 # means that the tag cache only has to worry about destroyed
2498 rtiprev = max((int(self.changelog.rev(node)) 2494 rtiprev = max((int(self.changelog.rev(node))
2499 for node in rbheads)) 2495 for node in rbheads))
2500 cache = branchmap.branchcache(rbranchmap, 2496 cache = branchmap.branchcache(rbranchmap,
2501 self[rtiprev].node(), 2497 self[rtiprev].node(),
2502 rtiprev) 2498 rtiprev)
2503 self._branchcache = cache 2499 self._branchcaches[None] = cache
2504 cache.write(self) 2500 cache.write(self.unfiltered())
2505 self.invalidate() 2501 self.invalidate()
2506 return len(self.heads()) + 1 2502 return len(self.heads()) + 1
2507 finally: 2503 finally:
2508 lock.release() 2504 lock.release()
2509 2505