hgext3rd/topic/__init__.py
changeset 1949 79c08d17a3d7
parent 1948 54810b543bf4
child 1950 99c1a26abf3f
equal deleted inserted replaced
1948:54810b543bf4 1949:79c08d17a3d7
    10 This is sort of similar to a bookmark, but it applies to a whole
    10 This is sort of similar to a bookmark, but it applies to a whole
    11 series instead of a single revision.
    11 series instead of a single revision.
    12 """
    12 """
    13 from __future__ import absolute_import
    13 from __future__ import absolute_import
    14 
    14 
    15 import contextlib
       
    16 import re
    15 import re
    17 
    16 
    18 from mercurial.i18n import _
    17 from mercurial.i18n import _
    19 from mercurial import (
    18 from mercurial import (
    20     branchmap,
    19     branchmap,
    90     destination.modsetup(ui)
    89     destination.modsetup(ui)
    91     topicrevset.modsetup(ui)
    90     topicrevset.modsetup(ui)
    92     discovery.modsetup(ui)
    91     discovery.modsetup(ui)
    93     setupimportexport(ui)
    92     setupimportexport(ui)
    94 
    93 
    95 @contextlib.contextmanager
       
    96 def usetopicmap(repo):
       
    97     """use awful monkey patching to update the topic cache"""
       
    98     oldbranchcache = branchmap.branchcache
       
    99     oldfilename = branchmap._filename
       
   100     oldread = branchmap.read
       
   101     oldcaches = getattr(repo, '_branchcaches', {})
       
   102     try:
       
   103         branchmap.branchcache = topicmap.topiccache
       
   104         branchmap._filename = topicmap._filename
       
   105         branchmap.read = topicmap.readtopicmap
       
   106         repo._branchcaches = getattr(repo, '_topiccaches', {})
       
   107         yield
       
   108         repo._topiccaches = repo._branchcaches
       
   109     finally:
       
   110         repo._branchcaches = oldcaches
       
   111         branchmap.branchcache = oldbranchcache
       
   112         branchmap._filename = oldfilename
       
   113         branchmap.read = oldread
       
   114 
       
   115 def cgapply(orig, repo, *args, **kwargs):
    94 def cgapply(orig, repo, *args, **kwargs):
   116     with usetopicmap(repo):
    95     with topicmap.usetopicmap(repo):
   117         return orig(repo, *args, **kwargs)
    96         return orig(repo, *args, **kwargs)
   118 
    97 
   119 def reposetup(ui, repo):
    98 def reposetup(ui, repo):
   120     orig = repo.__class__
    99     orig = repo.__class__
   121     if not isinstance(repo, localrepo.localrepository):
   100     if not isinstance(repo, localrepo.localrepository):
   146                 ctx.extra().get('amend_source') and
   125                 ctx.extra().get('amend_source') and
   147                 ctx.topic() and
   126                 ctx.topic() and
   148                 not self.currenttopic):
   127                 not self.currenttopic):
   149                 # we are amending and need to remove a topic
   128                 # we are amending and need to remove a topic
   150                 del ctx.extra()[constants.extrakey]
   129                 del ctx.extra()[constants.extrakey]
   151             with usetopicmap(self):
   130             with topicmap.usetopicmap(self):
   152                 return orig.commitctx(self, ctx, error=error)
   131                 return orig.commitctx(self, ctx, error=error)
   153 
   132 
   154         @property
   133         @property
   155         def topics(self):
   134         def topics(self):
   156             topics = set(['', self.currenttopic])
   135             topics = set(['', self.currenttopic])
   164             return self.vfs.tryread('topic')
   143             return self.vfs.tryread('topic')
   165 
   144 
   166         def branchmap(self, topic=True):
   145         def branchmap(self, topic=True):
   167             if not topic:
   146             if not topic:
   168                 super(topicrepo, self).branchmap()
   147                 super(topicrepo, self).branchmap()
   169             with usetopicmap(self):
   148             with topicmap.usetopicmap(self):
   170                 branchmap.updatecache(self)
   149                 branchmap.updatecache(self)
   171             return self._topiccaches[self.filtername]
   150             return self._topiccaches[self.filtername]
   172 
   151 
   173         def destroyed(self, *args, **kwargs):
   152         def destroyed(self, *args, **kwargs):
   174             with usetopicmap(self):
   153             with topicmap.usetopicmap(self):
   175                 return super(topicrepo, self).destroyed(*args, **kwargs)
   154                 return super(topicrepo, self).destroyed(*args, **kwargs)
   176 
   155 
   177         def invalidatecaches(self):
   156         def invalidatecaches(self):
   178             super(topicrepo, self).invalidatecaches()
   157             super(topicrepo, self).invalidatecaches()
   179             if '_topiccaches' in vars(self.unfiltered()):
   158             if '_topiccaches' in vars(self.unfiltered()):