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 |