comparison mercurial/localrepo.py @ 35248:c752fbe228fb

repoview: extract a factory function of proxy class This makes sure that dynamically-created class objects are isolated from local binding of repo instances. The type cache is moved to module level as it isn't tied to each instance.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 05 Dec 2017 21:50:33 +0900
parents 9ce4e01f58ee
children 137a08d82232
comparison
equal deleted inserted replaced
35247:9ce4e01f58ee 35248:c752fbe228fb
500 self.filteredrevcache = {} 500 self.filteredrevcache = {}
501 501
502 # post-dirstate-status hooks 502 # post-dirstate-status hooks
503 self._postdsstatus = [] 503 self._postdsstatus = []
504 504
505 # Cache of types representing filtered repos.
506 self._filteredrepotypes = weakref.WeakKeyDictionary()
507
508 # generic mapping between names and nodes 505 # generic mapping between names and nodes
509 self.names = namespaces.namespaces() 506 self.names = namespaces.namespaces()
510 507
511 # Key to signature value. 508 # Key to signature value.
512 self._sparsesignaturecache = {} 509 self._sparsesignaturecache = {}
678 Intended to be overwritten by filtered repo.""" 675 Intended to be overwritten by filtered repo."""
679 return self 676 return self
680 677
681 def filtered(self, name): 678 def filtered(self, name):
682 """Return a filtered version of a repository""" 679 """Return a filtered version of a repository"""
683 # Python <3.4 easily leaks types via __mro__. See 680 cls = repoview.newtype(self.unfiltered().__class__)
684 # https://bugs.python.org/issue17950. We cache dynamically 681 return cls(self, name)
685 # created types so this method doesn't leak on every
686 # invocation.
687
688 key = self.unfiltered().__class__
689 if key not in self._filteredrepotypes:
690 # Build a new type with the repoview mixin and the base
691 # class of this repo.
692 class filteredrepo(repoview.repoview, key):
693 pass
694 self._filteredrepotypes[key] = filteredrepo
695
696 return self._filteredrepotypes[key](self, name)
697 682
698 @repofilecache('bookmarks', 'bookmarks.current') 683 @repofilecache('bookmarks', 'bookmarks.current')
699 def _bookmarks(self): 684 def _bookmarks(self):
700 return bookmarks.bmstore(self) 685 return bookmarks.bmstore(self)
701 686