Mercurial > evolve
comparison hgext3rd/topic/__init__.py @ 3384:2b06f144b6e0
topics: add a new templatekeyword `topic`
This patch adds a new templatekeyword topic which can be used to list the topic
of the changeset when using commands which supports templating.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Tue, 09 Jan 2018 23:42:57 +0530 |
parents | 4138771105bb |
children | 5813075618b4 |
comparison
equal
deleted
inserted
replaced
3383:733e01473ec2 | 3384:2b06f144b6e0 |
---|---|
125 patch, | 125 patch, |
126 phases, | 126 phases, |
127 registrar, | 127 registrar, |
128 scmutil, | 128 scmutil, |
129 templatefilters, | 129 templatefilters, |
130 templatekw, | |
130 util, | 131 util, |
131 ) | 132 ) |
132 | 133 |
133 from . import ( | 134 from . import ( |
134 compat, | 135 compat, |
323 except (KeyError, AttributeError): | 324 except (KeyError, AttributeError): |
324 pass | 325 pass |
325 | 326 |
326 cmdutil.summaryhooks.add('topic', summaryhook) | 327 cmdutil.summaryhooks.add('topic', summaryhook) |
327 | 328 |
329 templatekw.keywords['topic'] = topickw | |
328 # Wrap workingctx extra to return the topic name | 330 # Wrap workingctx extra to return the topic name |
329 extensions.wrapfunction(context.workingctx, '__init__', wrapinit) | 331 extensions.wrapfunction(context.workingctx, '__init__', wrapinit) |
330 # Wrap changelog.add to drop empty topic | 332 # Wrap changelog.add to drop empty topic |
331 extensions.wrapfunction(changelog.changelog, 'add', wrapadd) | 333 extensions.wrapfunction(changelog.changelog, 'add', wrapadd) |
332 | 334 |
488 repo._topics = None | 490 repo._topics = None |
489 if util.safehasattr(repo, 'names'): | 491 if util.safehasattr(repo, 'names'): |
490 repo.names.addnamespace(namespaces.namespace( | 492 repo.names.addnamespace(namespaces.namespace( |
491 'topics', 'topic', namemap=_namemap, nodemap=_nodemap, | 493 'topics', 'topic', namemap=_namemap, nodemap=_nodemap, |
492 listnames=lambda repo: repo.topics)) | 494 listnames=lambda repo: repo.topics)) |
495 | |
496 def topickw(**args): | |
497 """:topic: String. The topic of the changeset""" | |
498 return args['ctx'].topic() | |
493 | 499 |
494 def wrapinit(orig, self, repo, *args, **kwargs): | 500 def wrapinit(orig, self, repo, *args, **kwargs): |
495 orig(self, repo, *args, **kwargs) | 501 orig(self, repo, *args, **kwargs) |
496 if getattr(repo, 'currenttopic', ''): | 502 if getattr(repo, 'currenttopic', ''): |
497 self._extra[constants.extrakey] = repo.currenttopic | 503 self._extra[constants.extrakey] = repo.currenttopic |