# HG changeset patch # User Pierre-Yves David # Date 1457914342 0 # Node ID dfaf0de6f4d8f493e7b2ee74aa97adc6e54332ea # Parent 68125d026b0754616f74a71c8779e90d6924686b topicmap: move the monkey patching into a context manager There is a couple of other place doing branchmap/topicmap update (of the served set), we'll have to set the monkey patching for them. This changeset is just doing the move to a context manager to make sure it is correct. diff -r 68125d026b07 -r dfaf0de6f4d8 src/topic/__init__.py --- a/src/topic/__init__.py Sat Mar 12 18:42:16 2016 +0000 +++ b/src/topic/__init__.py Mon Mar 14 00:12:22 2016 +0000 @@ -11,6 +11,7 @@ series instead of a single revision. """ import functools +import contextlib from mercurial.i18n import _ from mercurial import branchmap @@ -62,6 +63,23 @@ def uisetup(ui): destination.setupdest() +@contextlib.contextmanager +def usetopicmap(repo): + """use awful monkey patching to update the topic cache""" + oldbranchcache = branchmap.branchcache + oldfilename = branchmap._filename + oldcaches = getattr(repo, '_branchcaches', {}) + try: + branchmap.branchcache = topicmap.topiccache + branchmap._filename = topicmap._filename + repo._branchcaches = getattr(repo, '_topiccaches', {}) + yield + repo._topiccaches = repo._branchcaches + finally: + repo._branchcaches = oldcaches + branchmap.branchcache = oldbranchcache + branchmap._filename = oldfilename + def reposetup(ui, repo): orig = repo.__class__ if not isinstance(repo, localrepo.localrepository): @@ -105,20 +123,9 @@ 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', {}) + with usetopicmap(self): branchmap.updatecache(self) - self._topiccaches = self._branchcaches - return self._topiccaches[self.filtername] - finally: - self._branchcaches = oldcaches - branchmap.branchcache = oldbranchcache - branchmap._filename = oldfilename + return self._topiccaches[self.filtername] def invalidatecaches(self): super(topicrepo, self).invalidatecaches()