Mercurial > evolve
comparison hgext3rd/topic/__init__.py @ 3945:47dd383a9955
compat: use new style template keyword declaration
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 14 Aug 2018 19:15:35 +0200 |
parents | 38c9a050ba03 |
children | 9f8b99b3d9b5 |
comparison
equal
deleted
inserted
replaced
3944:4ef3800c9bf8 | 3945:47dd383a9955 |
---|---|
130 patch, | 130 patch, |
131 phases, | 131 phases, |
132 registrar, | 132 registrar, |
133 scmutil, | 133 scmutil, |
134 templatefilters, | 134 templatefilters, |
135 templatekw, | |
136 util, | 135 util, |
137 ) | 136 ) |
138 | 137 |
139 from . import ( | 138 from . import ( |
140 compat, | 139 compat, |
229 or not ui._knownconfig['devel'].get('random')): | 228 or not ui._knownconfig['devel'].get('random')): |
230 extraitem('devel', 'randomseed', | 229 extraitem('devel', 'randomseed', |
231 default=None, | 230 default=None, |
232 ) | 231 ) |
233 | 232 |
233 templatekeyword = registrar.templatekeyword() | |
234 | |
234 def _contexttopic(self, force=False): | 235 def _contexttopic(self, force=False): |
235 if not (force or self.mutable()): | 236 if not (force or self.mutable()): |
236 return '' | 237 return '' |
237 return self.extra().get(constants.extrakey, '') | 238 return self.extra().get(constants.extrakey, '') |
238 context.basectx.topic = _contexttopic | 239 context.basectx.topic = _contexttopic |
336 except (KeyError, AttributeError): | 337 except (KeyError, AttributeError): |
337 pass | 338 pass |
338 | 339 |
339 cmdutil.summaryhooks.add('topic', summaryhook) | 340 cmdutil.summaryhooks.add('topic', summaryhook) |
340 | 341 |
341 templatekw.keywords['topic'] = topickw | |
342 # Wrap workingctx extra to return the topic name | 342 # Wrap workingctx extra to return the topic name |
343 extensions.wrapfunction(context.workingctx, '__init__', wrapinit) | 343 extensions.wrapfunction(context.workingctx, '__init__', wrapinit) |
344 # Wrap changelog.add to drop empty topic | 344 # Wrap changelog.add to drop empty topic |
345 extensions.wrapfunction(changelog.changelog, 'add', wrapadd) | 345 extensions.wrapfunction(changelog.changelog, 'add', wrapadd) |
346 | 346 |
508 if util.safehasattr(repo, 'names'): | 508 if util.safehasattr(repo, 'names'): |
509 repo.names.addnamespace(namespaces.namespace( | 509 repo.names.addnamespace(namespaces.namespace( |
510 'topics', 'topic', namemap=_namemap, nodemap=_nodemap, | 510 'topics', 'topic', namemap=_namemap, nodemap=_nodemap, |
511 listnames=lambda repo: repo.topics)) | 511 listnames=lambda repo: repo.topics)) |
512 | 512 |
513 def topickw(**args): | 513 @templatekeyword('topic', requires={'ctx'}) |
514 def topickw(context, mapping): | |
514 """:topic: String. The topic of the changeset""" | 515 """:topic: String. The topic of the changeset""" |
515 return args['ctx'].topic() | 516 ctx = context.resource(mapping, 'ctx') |
517 return ctx.topic() | |
516 | 518 |
517 def wrapinit(orig, self, repo, *args, **kwargs): | 519 def wrapinit(orig, self, repo, *args, **kwargs): |
518 orig(self, repo, *args, **kwargs) | 520 orig(self, repo, *args, **kwargs) |
519 if getattr(repo, 'currenttopic', ''): | 521 if getattr(repo, 'currenttopic', ''): |
520 self._extra[constants.extrakey] = repo.currenttopic | 522 self._extra[constants.extrakey] = repo.currenttopic |