Mercurial > evolve
comparison hgext3rd/topic/__init__.py @ 5183:9ac6779d608c
topic: drop 4.5 compatibility for template keywords
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Sat, 07 Mar 2020 01:36:33 +0700 |
parents | 3a2a17b1985c |
children | a4d081923c81 |
comparison
equal
deleted
inserted
replaced
5182:df5e6e3884bc | 5183:9ac6779d608c |
---|---|
153 phases, | 153 phases, |
154 pycompat, | 154 pycompat, |
155 registrar, | 155 registrar, |
156 scmutil, | 156 scmutil, |
157 templatefilters, | 157 templatefilters, |
158 templatekw, | |
159 util, | 158 util, |
160 ) | 159 ) |
161 | 160 |
162 from . import ( | 161 from . import ( |
163 common, | 162 common, |
256 or not ui._knownconfig[b'devel'].get(b'random')): | 255 or not ui._knownconfig[b'devel'].get(b'random')): |
257 extraitem(b'devel', b'randomseed', | 256 extraitem(b'devel', b'randomseed', |
258 default=None, | 257 default=None, |
259 ) | 258 ) |
260 | 259 |
261 # we need to do old style declaration for <= 4.5 | |
262 templatekeyword = registrar.templatekeyword() | |
263 post45template = r'requires=' in templatekeyword.__doc__ | |
264 | |
265 def _contexttopic(self, force=False): | 260 def _contexttopic(self, force=False): |
266 if not (force or self.mutable()): | 261 if not (force or self.mutable()): |
267 return b'' | 262 return b'' |
268 return self.extra().get(constants.extrakey, b'') | 263 return self.extra().get(constants.extrakey, b'') |
269 context.basectx.topic = _contexttopic | 264 context.basectx.topic = _contexttopic |
371 except (KeyError, AttributeError): | 366 except (KeyError, AttributeError): |
372 pass | 367 pass |
373 | 368 |
374 cmdutil.summaryhooks.add(b'topic', summaryhook) | 369 cmdutil.summaryhooks.add(b'topic', summaryhook) |
375 | 370 |
376 if not post45template: | |
377 templatekw.keywords[b'topic'] = topickw | |
378 templatekw.keywords[b'topicidx'] = topicidxkw | |
379 # Wrap workingctx extra to return the topic name | 371 # Wrap workingctx extra to return the topic name |
380 extensions.wrapfunction(context.workingctx, '__init__', wrapinit) | 372 extensions.wrapfunction(context.workingctx, '__init__', wrapinit) |
381 # Wrap changelog.add to drop empty topic | 373 # Wrap changelog.add to drop empty topic |
382 extensions.wrapfunction(changelog.changelog, 'add', wrapadd) | 374 extensions.wrapfunction(changelog.changelog, 'add', wrapadd) |
383 | 375 |
590 if util.safehasattr(repo, 'names'): | 582 if util.safehasattr(repo, 'names'): |
591 repo.names.addnamespace(namespaces.namespace( | 583 repo.names.addnamespace(namespaces.namespace( |
592 b'topics', b'topic', namemap=_namemap, nodemap=_nodemap, | 584 b'topics', b'topic', namemap=_namemap, nodemap=_nodemap, |
593 listnames=lambda repo: repo.topics)) | 585 listnames=lambda repo: repo.topics)) |
594 | 586 |
595 if post45template: | 587 templatekeyword = registrar.templatekeyword() |
596 @templatekeyword(b'topic', requires={b'ctx'}) | 588 |
597 def topickw(context, mapping): | 589 @templatekeyword(b'topic', requires={b'ctx'}) |
598 """:topic: String. The topic of the changeset""" | 590 def topickw(context, mapping): |
599 ctx = context.resource(mapping, b'ctx') | 591 """:topic: String. The topic of the changeset""" |
600 return ctx.topic() | 592 ctx = context.resource(mapping, b'ctx') |
601 | 593 return ctx.topic() |
602 @templatekeyword(b'topicidx', requires={b'ctx'}) | 594 |
603 def topicidxkw(context, mapping): | 595 @templatekeyword(b'topicidx', requires={b'ctx'}) |
604 """:topicidx: Integer. Index of the changeset as a stack alias""" | 596 def topicidxkw(context, mapping): |
605 ctx = context.resource(mapping, b'ctx') | 597 """:topicidx: Integer. Index of the changeset as a stack alias""" |
606 return ctx.topicidx() | 598 ctx = context.resource(mapping, b'ctx') |
607 else: | 599 return ctx.topicidx() |
608 def topickw(**args): | |
609 """:topic: String. The topic of the changeset""" | |
610 return args[b'ctx'].topic() | |
611 | |
612 def topicidxkw(**args): | |
613 """:topicidx: Integer. Index of the changeset as a stack alias""" | |
614 return args[b'ctx'].topicidx() | |
615 | 600 |
616 def wrapinit(orig, self, repo, *args, **kwargs): | 601 def wrapinit(orig, self, repo, *args, **kwargs): |
617 orig(self, repo, *args, **kwargs) | 602 orig(self, repo, *args, **kwargs) |
618 if not hastopicext(repo): | 603 if not hastopicext(repo): |
619 return | 604 return |