comparison mercurial/templatekw.py @ 45868:f67741e8264b

templates: define a {onelinesummary} keyword It is sometimes useful to be able to use the configured `command-template.oneline-summary` in higher-level templates. For example, I would like to use it in an internal template that lists commits in a "review unit" (kind of a pull request). This patch adds support for that. We may want to define a way of formatting a context using a command-specific override (from `command-templates.oneline-summary.<command>`), but that will have to be a template function instead. I don't plan to do that, but I'm mentioning it now in case reviewers would prefer that we use a no-arg function (i.e. `{onelinesummary()}`) already today to prepare for that. Differential Revision: https://phab.mercurial-scm.org/D9314
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 12 Nov 2020 14:07:34 -0800
parents f95b23283760
children 89a2afe31e82
comparison
equal deleted inserted replaced
45867:774b1c0f2507 45868:f67741e8264b
632 if ctx.obsolete(): 632 if ctx.obsolete():
633 return b'obsolete' 633 return b'obsolete'
634 return b'' 634 return b''
635 635
636 636
637 @templatekeyword(b'onelinesummary', requires={b'ui', b'ctx'})
638 def showonelinesummary(context, mapping):
639 """String. A one-line summary for the ctx (not including trailing newline).
640 The default template be overridden in command-templates.oneline-summary."""
641 # Avoid cycle:
642 # mercurial.cmdutil -> mercurial.templatekw -> mercurial.cmdutil
643 from . import cmdutil
644
645 ui = context.resource(mapping, b'ui')
646 ctx = context.resource(mapping, b'ctx')
647 return cmdutil.format_changeset_summary(ui, ctx)
648
649
637 @templatekeyword(b'path', requires={b'fctx'}) 650 @templatekeyword(b'path', requires={b'fctx'})
638 def showpath(context, mapping): 651 def showpath(context, mapping):
639 """String. Repository-absolute path of the current file. (EXPERIMENTAL)""" 652 """String. Repository-absolute path of the current file. (EXPERIMENTAL)"""
640 fctx = context.resource(mapping, b'fctx') 653 fctx = context.resource(mapping, b'fctx')
641 return fctx.path() 654 return fctx.path()