# HG changeset patch # User Pierre-Yves David # Date 1459401917 25200 # Node ID 79c08d17a3d7b178e45fb6eb74106363533a89d0 # Parent 54810b543bf4d8bfa24b0867ccfb8689a81e7b95 topicmap: move the 'usetopicmap' context manager into the topicmap module There is no good reason to not have it gathered with the rest. diff -r 54810b543bf4 -r 79c08d17a3d7 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Wed Mar 30 22:05:49 2016 -0700 +++ b/hgext3rd/topic/__init__.py Wed Mar 30 22:25:17 2016 -0700 @@ -12,7 +12,6 @@ """ from __future__ import absolute_import -import contextlib import re from mercurial.i18n import _ @@ -92,28 +91,8 @@ discovery.modsetup(ui) setupimportexport(ui) -@contextlib.contextmanager -def usetopicmap(repo): - """use awful monkey patching to update the topic cache""" - oldbranchcache = branchmap.branchcache - oldfilename = branchmap._filename - oldread = branchmap.read - oldcaches = getattr(repo, '_branchcaches', {}) - try: - branchmap.branchcache = topicmap.topiccache - branchmap._filename = topicmap._filename - branchmap.read = topicmap.readtopicmap - repo._branchcaches = getattr(repo, '_topiccaches', {}) - yield - repo._topiccaches = repo._branchcaches - finally: - repo._branchcaches = oldcaches - branchmap.branchcache = oldbranchcache - branchmap._filename = oldfilename - branchmap.read = oldread - def cgapply(orig, repo, *args, **kwargs): - with usetopicmap(repo): + with topicmap.usetopicmap(repo): return orig(repo, *args, **kwargs) def reposetup(ui, repo): @@ -148,7 +127,7 @@ not self.currenttopic): # we are amending and need to remove a topic del ctx.extra()[constants.extrakey] - with usetopicmap(self): + with topicmap.usetopicmap(self): return orig.commitctx(self, ctx, error=error) @property @@ -166,12 +145,12 @@ def branchmap(self, topic=True): if not topic: super(topicrepo, self).branchmap() - with usetopicmap(self): + with topicmap.usetopicmap(self): branchmap.updatecache(self) return self._topiccaches[self.filtername] def destroyed(self, *args, **kwargs): - with usetopicmap(self): + with topicmap.usetopicmap(self): return super(topicrepo, self).destroyed(*args, **kwargs) def invalidatecaches(self): diff -r 54810b543bf4 -r 79c08d17a3d7 hgext3rd/topic/topicmap.py --- a/hgext3rd/topic/topicmap.py Wed Mar 30 22:05:49 2016 -0700 +++ b/hgext3rd/topic/topicmap.py Wed Mar 30 22:25:17 2016 -0700 @@ -1,3 +1,5 @@ +import contextlib + from mercurial.node import hex, bin, nullid from mercurial import ( branchmap, @@ -35,6 +37,29 @@ key = s.digest() return key +@contextlib.contextmanager +def usetopicmap(repo): + """use awful monkey patching to ensure topic map usage + + During the extend of the context block, The topicmap should be used and + updated instead of the branchmap.""" + oldbranchcache = branchmap.branchcache + oldfilename = branchmap._filename + oldread = branchmap.read + oldcaches = getattr(repo, '_branchcaches', {}) + try: + branchmap.branchcache = topiccache + branchmap._filename = _filename + branchmap.read = readtopicmap + repo._branchcaches = getattr(repo, '_topiccaches', {}) + yield + repo._topiccaches = repo._branchcaches + finally: + repo._branchcaches = oldcaches + branchmap.branchcache = oldbranchcache + branchmap._filename = oldfilename + branchmap.read = oldread + class topiccache(oldbranchcache): def __init__(self, *args, **kwargs):