hgext3rd/topic/__init__.py
branchmercurial-4.5
changeset 4080 7567b58390d7
parent 4078 da6ce6d446b9
child 4083 8d8f08245f97
equal deleted inserted replaced
4075:dc247e648f43 4080:7567b58390d7
   132     patch,
   132     patch,
   133     phases,
   133     phases,
   134     registrar,
   134     registrar,
   135     scmutil,
   135     scmutil,
   136     templatefilters,
   136     templatefilters,
       
   137     templatekw,
   137     util,
   138     util,
   138 )
   139 )
   139 
   140 
   140 from . import (
   141 from . import (
   141     compat,
   142     compat,
   225                 or not ui._knownconfig['devel'].get('random')):
   226                 or not ui._knownconfig['devel'].get('random')):
   226             extraitem('devel', 'randomseed',
   227             extraitem('devel', 'randomseed',
   227                       default=None,
   228                       default=None,
   228             )
   229             )
   229 
   230 
       
   231 # we need to do old style declaration for <= 4.5
   230 templatekeyword = registrar.templatekeyword()
   232 templatekeyword = registrar.templatekeyword()
       
   233 post45template = 'requires=' in templatekeyword.__doc__
   231 
   234 
   232 def _contexttopic(self, force=False):
   235 def _contexttopic(self, force=False):
   233     if not (force or self.mutable()):
   236     if not (force or self.mutable()):
   234         return ''
   237         return ''
   235     return self.extra().get(constants.extrakey, '')
   238     return self.extra().get(constants.extrakey, '')
   348     except (KeyError, AttributeError):
   351     except (KeyError, AttributeError):
   349         pass
   352         pass
   350 
   353 
   351     cmdutil.summaryhooks.add('topic', summaryhook)
   354     cmdutil.summaryhooks.add('topic', summaryhook)
   352 
   355 
       
   356     if not post45template:
       
   357         templatekw.keywords['topic'] = topickw
   353     # Wrap workingctx extra to return the topic name
   358     # Wrap workingctx extra to return the topic name
   354     extensions.wrapfunction(context.workingctx, '__init__', wrapinit)
   359     extensions.wrapfunction(context.workingctx, '__init__', wrapinit)
   355     # Wrap changelog.add to drop empty topic
   360     # Wrap changelog.add to drop empty topic
   356     extensions.wrapfunction(changelog.changelog, 'add', wrapadd)
   361     extensions.wrapfunction(changelog.changelog, 'add', wrapadd)
   357 
   362 
   519     if util.safehasattr(repo, 'names'):
   524     if util.safehasattr(repo, 'names'):
   520         repo.names.addnamespace(namespaces.namespace(
   525         repo.names.addnamespace(namespaces.namespace(
   521             'topics', 'topic', namemap=_namemap, nodemap=_nodemap,
   526             'topics', 'topic', namemap=_namemap, nodemap=_nodemap,
   522             listnames=lambda repo: repo.topics))
   527             listnames=lambda repo: repo.topics))
   523 
   528 
   524 @templatekeyword('topic', requires={'ctx'})
   529 if post45template:
   525 def topickw(context, mapping):
   530     @templatekeyword('topic', requires={'ctx'})
   526     """:topic: String. The topic of the changeset"""
   531     def topickw(context, mapping):
   527     ctx = context.resource(mapping, 'ctx')
   532         """:topic: String. The topic of the changeset"""
   528     return ctx.topic()
   533         ctx = context.resource(mapping, 'ctx')
       
   534         return ctx.topic()
       
   535 else:
       
   536     def topickw(**args):
       
   537         """:topic: String. The topic of the changeset"""
       
   538         return args['ctx'].topic()
   529 
   539 
   530 def wrapinit(orig, self, repo, *args, **kwargs):
   540 def wrapinit(orig, self, repo, *args, **kwargs):
   531     orig(self, repo, *args, **kwargs)
   541     orig(self, repo, *args, **kwargs)
   532     if getattr(repo, 'currenttopic', ''):
   542     if getattr(repo, 'currenttopic', ''):
   533         self._extra[constants.extrakey] = repo.currenttopic
   543         self._extra[constants.extrakey] = repo.currenttopic