src/topic/__init__.py
changeset 1885 d49f75eab6a3
parent 1884 8a53f99d9061
child 1886 0504e76bfbd9
--- a/src/topic/__init__.py	Mon Mar 14 20:18:09 2016 -0400
+++ b/src/topic/__init__.py	Sat Mar 12 15:36:17 2016 +0000
@@ -26,10 +26,12 @@
 from mercurial import patch
 from mercurial import phases
 from mercurial import util
+from mercurial import branchmap
 
 from . import constants
 from . import revset as topicrevset
 from . import destination
+from . import topicmap
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -92,6 +94,29 @@
         def currenttopic(self):
             return self.vfs.tryread('topic')
 
+        def branchmap(self, topic=True):
+            if not topic:
+                super(topicrepo, self).branchmap()
+            oldbranchcache = branchmap.branchcache
+            oldfilename = branchmap._filename
+            oldcaches =  getattr(self, '_branchcaches', {})
+            try:
+                branchmap.branchcache = topicmap.topiccache
+                branchmap._filename = topicmap._filename
+                self._branchcaches = getattr(self, '_topiccaches', {})
+                branchmap.updatecache(self)
+                self._topiccaches = self._branchcaches
+                return self._topiccaches[self.filtername]
+            finally:
+                self._branchcaches = oldcaches
+                branchmap.branchcache = oldbranchcache
+                branchmap._filename = oldfilename
+
+        def invalidatecaches(self):
+            super(topicrepo, self).invalidatecaches()
+            if '_topiccaches' in vars(self.unfiltered()):
+                self.unfiltered()._topiccaches.clear()
+
     repo.__class__ = topicrepo
     if util.safehasattr(repo, 'names'):
         repo.names.addnamespace(namespaces.namespace(