hgext3rd/topic/__init__.py
changeset 1904 f52c02bf47b7
parent 1903 58cdf061d49a
child 1907 95874e8fc5f2
equal deleted inserted replaced
1903:58cdf061d49a 1904:f52c02bf47b7
    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 import functools
    13 import functools
    14 import contextlib
    14 import contextlib
       
    15 import re
    15 
    16 
    16 from mercurial.i18n import _
    17 from mercurial.i18n import _
    17 from mercurial import branchmap
    18 from mercurial import branchmap
    18 from mercurial import bundle2
    19 from mercurial import bundle2
    19 from mercurial import changegroup
    20 from mercurial import changegroup
    49 
    50 
    50 def _contexttopic(self):
    51 def _contexttopic(self):
    51     return self.extra().get(constants.extrakey, '')
    52     return self.extra().get(constants.extrakey, '')
    52 context.basectx.topic = _contexttopic
    53 context.basectx.topic = _contexttopic
    53 
    54 
       
    55 topicrev = re.compile(r'^t\d+$')
       
    56 
       
    57 
    54 def _namemap(repo, name):
    58 def _namemap(repo, name):
       
    59     if topicrev.match(name):
       
    60         idx = int(name[1:])
       
    61         topic = repo.currenttopic
       
    62         if not topic:
       
    63             raise error.Abort(_('cannot resolve "%s": no active topic') % name)
       
    64         revs = list(stack.getstack(repo, topic))
       
    65         try:
       
    66             r = revs[idx]
       
    67         except IndexError:
       
    68             msg = _('cannot resolve "%s": topic "%s" has only %d changesets')
       
    69             raise error.Abort(msg % (name, topic, len(revs)))
       
    70         return [repo[r].node()]
    55     return [ctx.node() for ctx in
    71     return [ctx.node() for ctx in
    56             repo.set('not public() and extra(topic, %s)', name)]
    72             repo.set('not public() and extra(topic, %s)', name)]
    57 
    73 
    58 def _nodemap(repo, node):
    74 def _nodemap(repo, node):
    59     ctx = repo[node]
    75     ctx = repo[node]