templatekw.py
1012 lines
| 33.5 KiB
| text/x-python
|
PythonLexer
/ mercurial / templatekw.py
|
r10053 | # templatekw.py - common changeset template keywords | ||
# | ||||
|
r47575 | # Copyright 2005-2009 Olivia Mackall <olivia@selenic.com> | ||
|
r10053 | # | ||
# This software may be used and distributed according to the terms of the | ||||
|
r10264 | # GNU General Public License version 2 or any later version. | ||
|
r10053 | |||
|
r25984 | from __future__ import absolute_import | ||
|
r31807 | from .i18n import _ | ||
|
r32656 | from .node import ( | ||
hex, | ||||
|
r39832 | wdirrev, | ||
|
r32656 | ) | ||
|
r25984 | from . import ( | ||
|
r38607 | diffutil, | ||
|
r28239 | encoding, | ||
|
r25984 | error, | ||
hbisect, | ||||
|
r35213 | i18n, | ||
|
r32879 | obsutil, | ||
|
r25984 | patch, | ||
|
r32972 | pycompat, | ||
|
r28539 | registrar, | ||
|
r25984 | scmutil, | ||
|
r36939 | templateutil, | ||
|
r25984 | util, | ||
) | ||||
r47806 | from .utils import ( | |||
stringutil, | ||||
urlutil, | ||||
) | ||||
|
r10053 | |||
|
r36939 | _hybrid = templateutil.hybrid | ||
hybriddict = templateutil.hybriddict | ||||
hybridlist = templateutil.hybridlist | ||||
compatdict = templateutil.compatdict | ||||
compatlist = templateutil.compatlist | ||||
|
r37086 | _showcompatlist = templateutil._showcompatlist | ||
|
r43346 | |||
|
r36614 | def getlatesttags(context, mapping, pattern=None): | ||
|
r10057 | '''return date, distance and name for the latest tag of rev''' | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
cache = context.resource(mapping, b'cache') | ||||
|
r10057 | |||
|
r43347 | cachename = b'latesttags' | ||
|
r26482 | if pattern is not None: | ||
|
r43347 | cachename += b'-' + pattern | ||
|
r37102 | match = stringutil.stringmatcher(pattern)[2] | ||
|
r26482 | else: | ||
match = util.always | ||||
if cachename not in cache: | ||||
|
r10057 | # Cache mapping from rev to a tuple with tag date, tag | ||
# distance and tag name | ||||
|
r43347 | cache[cachename] = {-1: (0, 0, [b'null'])} | ||
|
r26482 | latesttags = cache[cachename] | ||
|
r10057 | |||
rev = ctx.rev() | ||||
todo = [rev] | ||||
while todo: | ||||
rev = todo.pop() | ||||
if rev in latesttags: | ||||
continue | ||||
ctx = repo[rev] | ||||
|
r43346 | tags = [ | ||
t | ||||
for t in ctx.tags() | ||||
|
r43347 | if (repo.tagtype(t) and repo.tagtype(t) != b'local' and match(t)) | ||
|
r43346 | ] | ||
|
r10057 | if tags: | ||
|
r25700 | latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)] | ||
|
r10057 | continue | ||
try: | ||||
|
r33866 | ptags = [latesttags[p.rev()] for p in ctx.parents()] | ||
if len(ptags) > 1: | ||||
if ptags[0][2] == ptags[1][2]: | ||||
# The tuples are laid out so the right one can be found by | ||||
# comparison in this case. | ||||
pdate, pdist, ptag = max(ptags) | ||||
else: | ||||
|
r43346 | |||
|
r33866 | def key(x): | ||
|
r41336 | tag = x[2][0] | ||
if ctx.rev() is None: | ||||
# only() doesn't support wdir | ||||
prevs = [c.rev() for c in ctx.parents()] | ||||
|
r43347 | changes = repo.revs(b'only(%ld, %s)', prevs, tag) | ||
|
r41336 | changessincetag = len(changes) + 1 | ||
else: | ||||
|
r43347 | changes = repo.revs(b'only(%d, %s)', ctx.rev(), tag) | ||
|
r41336 | changessincetag = len(changes) | ||
|
r33866 | # Smallest number of changes since tag wins. Date is | ||
# used as tiebreaker. | ||||
return [-changessincetag, x[0]] | ||||
|
r43346 | |||
|
r33866 | pdate, pdist, ptag = max(ptags, key=key) | ||
else: | ||||
pdate, pdist, ptag = ptags[0] | ||||
|
r10057 | except KeyError: | ||
# Cache miss - recurse | ||||
todo.append(rev) | ||||
todo.extend(p.rev() for p in ctx.parents()) | ||||
continue | ||||
latesttags[rev] = pdate, pdist + 1, ptag | ||||
return latesttags[rev] | ||||
|
r43346 | |||
|
r35213 | def getlogcolumns(): | ||
"""Return a dict of log column labels""" | ||||
_ = pycompat.identity # temporarily disable gettext | ||||
# i18n: column positioning for "hg log" | ||||
|
r43346 | columns = _( | ||
|
r43347 | b'bookmark: %s\n' | ||
b'branch: %s\n' | ||||
b'changeset: %s\n' | ||||
b'copies: %s\n' | ||||
b'date: %s\n' | ||||
b'extra: %s=%s\n' | ||||
b'files+: %s\n' | ||||
b'files-: %s\n' | ||||
b'files: %s\n' | ||||
b'instability: %s\n' | ||||
b'manifest: %s\n' | ||||
b'obsolete: %s\n' | ||||
b'parent: %s\n' | ||||
b'phase: %s\n' | ||||
b'summary: %s\n' | ||||
b'tag: %s\n' | ||||
b'user: %s\n' | ||||
|
r43346 | ) | ||
return dict( | ||||
zip( | ||||
|
r43347 | [s.split(b':', 1)[0] for s in columns.splitlines()], | ||
|
r43346 | i18n._(columns).splitlines(True), | ||
) | ||||
) | ||||
|
r35213 | |||
|
r40508 | # basic internal templates | ||
|
r43347 | _changeidtmpl = b'{rev}:{node|formatnode}' | ||
|
r40508 | |||
|
r31171 | # default templates internally used for rendering of lists | ||
defaulttempl = { | ||||
|
r43347 | b'parent': _changeidtmpl + b' ', | ||
b'manifest': _changeidtmpl, | ||||
b'file_copy': b'{name} ({source})', | ||||
b'envvar': b'{key}={value}', | ||||
b'extra': b'{key}={value|stringescape}', | ||||
|
r31171 | } | ||
# filecopy is preserved for compatibility reasons | ||||
|
r43347 | defaulttempl[b'filecopy'] = defaulttempl[b'file_copy'] | ||
|
r31171 | |||
|
r36463 | # keywords are callables (see registrar.templatekeyword for details) | ||
|
r28539 | keywords = {} | ||
templatekeyword = registrar.templatekeyword(keywords) | ||||
|
r43346 | |||
|
r43347 | @templatekeyword(b'author', requires={b'ctx'}) | ||
|
r36463 | def showauthor(context, mapping): | ||
|
r38983 | """Alias for ``{user}``""" | ||
return showuser(context, mapping) | ||||
|
r10054 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'bisect', requires={b'repo', b'ctx'}) | ||
|
r36531 | def showbisect(context, mapping): | ||
|
r28539 | """String. The changeset bisection status.""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r15155 | return hbisect.label(repo, ctx.node()) | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'branch', requires={b'ctx'}) | ||
|
r36531 | def showbranch(context, mapping): | ||
|
r28539 | """String. The name of the branch on which the changeset was | ||
|
r13585 | committed. | ||
""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r36531 | return ctx.branch() | ||
|
r13156 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'branches', requires={b'ctx'}) | ||
|
r36609 | def showbranches(context, mapping): | ||
|
r28539 | """List of strings. The name of the branch on which the | ||
|
r13585 | changeset was committed. Will be empty if the branch name was | ||
|
r26437 | default. (DEPRECATED) | ||
|
r13585 | """ | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r36609 | branch = ctx.branch() | ||
|
r43347 | if branch != b'default': | ||
|
r43346 | return compatlist( | ||
|
r43347 | context, mapping, b'branch', [branch], plural=b'branches' | ||
|
r43346 | ) | ||
|
r43347 | return compatlist(context, mapping, b'branch', [], plural=b'branches') | ||
|
r10054 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'bookmarks', requires={b'repo', b'ctx'}) | ||
|
r36616 | def showbookmarks(context, mapping): | ||
|
r28539 | """List of strings. Any bookmarks associated with the | ||
|
r25348 | changeset. Also sets 'active', the name of the active bookmark. | ||
|
r13592 | """ | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r36616 | bookmarks = ctx.bookmarks() | ||
|
r25348 | active = repo._activebookmark | ||
|
r43347 | makemap = lambda v: {b'bookmark': v, b'active': active, b'current': active} | ||
f = _showcompatlist(context, mapping, b'bookmark', bookmarks) | ||||
|
r34329 | return _hybrid(f, bookmarks, makemap, pycompat.identity) | ||
|
r13386 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'children', requires={b'ctx'}) | ||
|
r36538 | def showchildren(context, mapping): | ||
|
r28539 | """List of strings. The children of the changeset.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
childrevs = [b'%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()] | ||||
return compatlist( | ||||
context, mapping, b'children', childrevs, element=b'child' | ||||
) | ||||
|
r11655 | |||
|
r43346 | |||
|
r25013 | # Deprecated, but kept alive for help generation a purpose. | ||
|
r43347 | @templatekeyword(b'currentbookmark', requires={b'repo', b'ctx'}) | ||
|
r36531 | def showcurrentbookmark(context, mapping): | ||
|
r34657 | """String. The active bookmark, if it is associated with the changeset. | ||
(DEPRECATED)""" | ||||
|
r36531 | return showactivebookmark(context, mapping) | ||
|
r25013 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'activebookmark', requires={b'repo', b'ctx'}) | ||
|
r36531 | def showactivebookmark(context, mapping): | ||
|
r34657 | """String. The active bookmark, if it is associated with the changeset.""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r36531 | active = repo._activebookmark | ||
if active and active in ctx.bookmarks(): | ||||
|
r25387 | return active | ||
|
r43347 | return b'' | ||
|
r21896 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'date', requires={b'ctx'}) | ||
|
r36531 | def showdate(context, mapping): | ||
|
r28539 | """Date information. The date when the changeset was committed.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r38318 | # the default string format is '<float(unixtime)><tzoffset>' because | ||
# python-hglib splits date at decimal separator. | ||||
|
r43347 | return templateutil.date(ctx.date(), showfmt=b'%d.0%d') | ||
|
r10054 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'desc', requires={b'ctx'}) | ||
|
r36531 | def showdescription(context, mapping): | ||
|
r28539 | """String. The text of the changeset description.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r28239 | s = ctx.description() | ||
if isinstance(s, encoding.localstr): | ||||
# try hard to preserve utf-8 bytes | ||||
return encoding.tolocal(encoding.fromlocal(s).strip()) | ||||
|
r37966 | elif isinstance(s, encoding.safelocalstr): | ||
return encoding.safelocalstr(s.strip()) | ||||
|
r28239 | else: | ||
return s.strip() | ||||
|
r10054 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'diffstat', requires={b'ui', b'ctx'}) | ||
|
r36531 | def showdiffstat(context, mapping): | ||
|
r28539 | """String. Statistics of changes with the following format: | ||
|
r13585 | "modified files: +added/-removed lines" | ||
""" | ||||
|
r43347 | ui = context.resource(mapping, b'ui') | ||
ctx = context.resource(mapping, b'ctx') | ||||
diffopts = diffutil.diffallopts(ui, {b'noprefix': False}) | ||||
|
r38583 | diff = ctx.diff(opts=diffopts) | ||
|
r38538 | stats = patch.diffstatdata(util.iterlines(diff)) | ||
|
r14437 | maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats) | ||
|
r43347 | return b'%d: +%d/-%d' % (len(stats), adds, removes) | ||
|
r10055 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'envvars', requires={b'ui'}) | ||
|
r36537 | def showenvvars(context, mapping): | ||
|
r30833 | """A dictionary of environment variables. (EXPERIMENTAL)""" | ||
|
r43347 | ui = context.resource(mapping, b'ui') | ||
|
r36460 | env = ui.exportableenviron() | ||
|
r30833 | env = util.sortdict((k, env[k]) for k in sorted(env)) | ||
|
r43347 | return compatdict(context, mapping, b'envvar', env, plural=b'envvars') | ||
|
r30833 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'extras', requires={b'ctx'}) | ||
|
r36616 | def showextras(context, mapping): | ||
|
r28539 | """List of dicts with key, value entries of the 'extras' | ||
|
r20015 | field of this changeset.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r36616 | extras = ctx.extra() | ||
|
r24237 | extras = util.sortdict((k, extras[k]) for k in sorted(extras)) | ||
|
r43347 | makemap = lambda k: {b'key': k, b'value': extras[k]} | ||
|
r24238 | c = [makemap(k) for k in extras] | ||
|
r43347 | f = _showcompatlist(context, mapping, b'extra', c, plural=b'extras') | ||
|
r43346 | return _hybrid( | ||
f, | ||||
extras, | ||||
makemap, | ||||
|
r43347 | lambda k: b'%s=%s' % (k, stringutil.escapestr(extras[k])), | ||
|
r43346 | ) | ||
|
r10054 | |||
|
r39635 | def _getfilestatus(context, mapping, listall=False): | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
revcache = context.resource(mapping, b'revcache') | ||||
if b'filestatus' not in revcache or revcache[b'filestatusall'] < listall: | ||||
|
r43346 | stat = ctx.p1().status( | ||
ctx, listignored=listall, listclean=listall, listunknown=listall | ||||
) | ||||
|
r43347 | revcache[b'filestatus'] = stat | ||
revcache[b'filestatusall'] = listall | ||||
return revcache[b'filestatus'] | ||||
|
r39633 | |||
|
r43346 | |||
|
r39636 | def _getfilestatusmap(context, mapping, listall=False): | ||
|
r43347 | revcache = context.resource(mapping, b'revcache') | ||
if b'filestatusmap' not in revcache or revcache[b'filestatusall'] < listall: | ||||
|
r39636 | stat = _getfilestatus(context, mapping, listall=listall) | ||
|
r43347 | revcache[b'filestatusmap'] = statmap = {} | ||
for char, files in zip(pycompat.iterbytestr(b'MAR!?IC'), stat): | ||||
|
r39636 | statmap.update((f, char) for f in files) | ||
|
r43347 | return revcache[b'filestatusmap'] # {path: statchar} | ||
|
r39636 | |||
|
r43346 | |||
|
r43347 | @templatekeyword( | ||
b'file_copies', requires={b'repo', b'ctx', b'cache', b'revcache'} | ||||
) | ||||
|
r36608 | def showfilecopies(context, mapping): | ||
|
r28539 | """List of strings. Files copied in this changeset with | ||
|
r13585 | their sources. | ||
""" | ||||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
cache = context.resource(mapping, b'cache') | ||||
copies = context.resource(mapping, b'revcache').get(b'copies') | ||||
|
r10060 | if copies is None: | ||
|
r43347 | if b'getcopies' not in cache: | ||
cache[b'getcopies'] = scmutil.getcopiesfn(repo) | ||||
getcopies = cache[b'getcopies'] | ||||
|
r42703 | copies = getcopies(ctx) | ||
|
r43346 | return templateutil.compatfilecopiesdict( | ||
|
r43347 | context, mapping, b'file_copy', copies | ||
|
r43346 | ) | ||
|
r10060 | |||
# showfilecopiesswitch() displays file copies only if copy records are | ||||
# provided before calling the templater, usually with a --copies | ||||
# command line switch. | ||||
|
r43347 | @templatekeyword(b'file_copies_switch', requires={b'revcache'}) | ||
|
r36608 | def showfilecopiesswitch(context, mapping): | ||
|
r28539 | """List of strings. Like "file_copies" but displayed | ||
|
r13585 | only if the --copied switch is set. | ||
""" | ||||
|
r43347 | copies = context.resource(mapping, b'revcache').get(b'copies') or [] | ||
|
r43346 | return templateutil.compatfilecopiesdict( | ||
|
r43347 | context, mapping, b'file_copy', copies | ||
|
r43346 | ) | ||
|
r10058 | |||
|
r43347 | @templatekeyword(b'file_adds', requires={b'ctx', b'revcache'}) | ||
|
r42563 | def showfileadds(context, mapping): | ||
"""List of strings. Files added by this changeset.""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r43346 | return templateutil.compatfileslist( | ||
|
r43347 | context, mapping, b'file_add', ctx.filesadded() | ||
|
r43346 | ) | ||
|
r42563 | |||
|
r43347 | @templatekeyword(b'file_dels', requires={b'ctx', b'revcache'}) | ||
|
r36609 | def showfiledels(context, mapping): | ||
|
r28539 | """List of strings. Files removed by this changeset.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r43346 | return templateutil.compatfileslist( | ||
|
r43347 | context, mapping, b'file_del', ctx.filesremoved() | ||
|
r43346 | ) | ||
|
r10056 | |||
|
r43347 | @templatekeyword(b'file_mods', requires={b'ctx', b'revcache'}) | ||
|
r36609 | def showfilemods(context, mapping): | ||
|
r28539 | """List of strings. Files modified by this changeset.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r43346 | return templateutil.compatfileslist( | ||
|
r43347 | context, mapping, b'file_mod', ctx.filesmodified() | ||
|
r43346 | ) | ||
|
r10056 | |||
|
r43347 | @templatekeyword(b'files', requires={b'ctx'}) | ||
|
r36609 | def showfiles(context, mapping): | ||
|
r28539 | """List of strings. All files modified, added, or removed by this | ||
|
r13585 | changeset. | ||
""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
return templateutil.compatfileslist(context, mapping, b'file', ctx.files()) | ||||
|
r10054 | |||
|
r43346 | |||
|
r44819 | @templatekeyword(b'graphnode', requires={b'repo', b'ctx', b'cache'}) | ||
|
r36531 | def showgraphnode(context, mapping): | ||
|
r34657 | """String. The character representing the changeset node in an ASCII | ||
revision graph.""" | ||||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r44819 | cache = context.resource(mapping, b'cache') | ||
return getgraphnode(repo, ctx, cache) | ||||
|
r36530 | |||
|
r43346 | |||
|
r44819 | def getgraphnode(repo, ctx, cache): | ||
return getgraphnodecurrent(repo, ctx, cache) or getgraphnodesymbol(ctx) | ||||
r37927 | ||||
|
r43346 | |||
|
r44819 | def getgraphnodecurrent(repo, ctx, cache): | ||
|
r27215 | wpnodes = repo.dirstate.parents() | ||
|
r47771 | if wpnodes[1] == repo.nullid: | ||
|
r27215 | wpnodes = wpnodes[:1] | ||
|
r27214 | if ctx.node() in wpnodes: | ||
|
r43347 | return b'@' | ||
r37927 | else: | |||
|
r45206 | merge_nodes = cache.get(b'merge_nodes') | ||
if merge_nodes is None: | ||||
|
r45383 | from . import mergestate as mergestatemod | ||
|
r44819 | |||
|
r45383 | mergestate = mergestatemod.mergestate.read(repo) | ||
|
r46020 | if mergestate.unresolvedcount(): | ||
|
r44819 | merge_nodes = (mergestate.local, mergestate.other) | ||
|
r45206 | else: | ||
merge_nodes = () | ||||
|
r44819 | cache[b'merge_nodes'] = merge_nodes | ||
if ctx.node() in merge_nodes: | ||||
return b'%' | ||||
|
r43347 | return b'' | ||
r37927 | ||||
|
r43346 | |||
r37927 | def getgraphnodesymbol(ctx): | |||
if ctx.obsolete(): | ||||
|
r43347 | return b'x' | ||
r35524 | elif ctx.isunstable(): | |||
|
r43347 | return b'*' | ||
|
r27214 | elif ctx.closesbranch(): | ||
|
r43347 | return b'_' | ||
|
r27214 | else: | ||
|
r43347 | return b'o' | ||
|
r27214 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'graphwidth', requires=()) | ||
|
r36531 | def showgraphwidth(context, mapping): | ||
|
r33860 | """Integer. The width of the graph drawn by 'log --graph' or zero.""" | ||
|
r36459 | # just hosts documentation; should be overridden by template mapping | ||
return 0 | ||||
|
r33860 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'index', requires=()) | ||
|
r36531 | def showindex(context, mapping): | ||
|
r31807 | """Integer. The current iteration of the loop. (0 indexed)""" | ||
# just hosts documentation; should be overridden by template mapping | ||||
|
r43347 | raise error.Abort(_(b"can't use index in this context")) | ||
|
r31807 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'latesttag', requires={b'repo', b'ctx', b'cache'}) | ||
|
r36614 | def showlatesttag(context, mapping): | ||
|
r28539 | """List of strings. The global tags on the most recent globally | ||
|
r31850 | tagged ancestor of this changeset. If no such tags exist, the list | ||
consists of the single string "null". | ||||
|
r13585 | """ | ||
|
r36614 | return showlatesttags(context, mapping, None) | ||
|
r10057 | |||
|
r43346 | |||
|
r36614 | def showlatesttags(context, mapping, pattern): | ||
|
r26484 | """helper method for the latesttag keyword and function""" | ||
|
r36614 | latesttags = getlatesttags(context, mapping, pattern) | ||
|
r26484 | |||
# latesttag[0] is an implementation detail for sorting csets on different | ||||
# branches in a stable manner- it is the date the tagged cset was created, | ||||
# not the date the tag was created. Therefore it isn't made visible here. | ||||
makemap = lambda v: { | ||||
|
r43347 | b'changes': _showchangessincetag, | ||
b'distance': latesttags[1], | ||||
b'latesttag': v, # BC with {latesttag % '{latesttag}'} | ||||
b'tag': v, | ||||
|
r26484 | } | ||
tags = latesttags[2] | ||||
|
r43347 | f = _showcompatlist(context, mapping, b'latesttag', tags, separator=b':') | ||
|
r34329 | return _hybrid(f, tags, makemap, pycompat.identity) | ||
|
r26484 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'latesttagdistance', requires={b'repo', b'ctx', b'cache'}) | ||
|
r36614 | def showlatesttagdistance(context, mapping): | ||
|
r28539 | """Integer. Longest path to the latest tag.""" | ||
|
r36614 | return getlatesttags(context, mapping)[1] | ||
|
r10057 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'changessincelatesttag', requires={b'repo', b'ctx', b'cache'}) | ||
|
r36614 | def showchangessincelatesttag(context, mapping): | ||
|
r28539 | """Integer. All ancestors not in the latest tag.""" | ||
|
r37092 | tag = getlatesttags(context, mapping)[2][0] | ||
|
r43347 | mapping = context.overlaymap(mapping, {b'tag': tag}) | ||
|
r36614 | return _showchangessincetag(context, mapping) | ||
|
r26483 | |||
|
r43346 | |||
|
r36614 | def _showchangessincetag(context, mapping): | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r25724 | offset = 0 | ||
revs = [ctx.rev()] | ||||
|
r43347 | tag = context.symbol(mapping, b'tag') | ||
|
r25724 | |||
# The only() revset doesn't currently support wdir() | ||||
if ctx.rev() is None: | ||||
offset = 1 | ||||
revs = [p.rev() for p in ctx.parents()] | ||||
|
r43347 | return len(repo.revs(b'only(%ld, %s)', revs, tag)) + offset | ||
|
r25724 | |||
|
r43346 | |||
|
r36614 | # teach templater latesttags.changes is switched to (context, mapping) API | ||
|
r43347 | _showchangessincetag._requires = {b'repo', b'ctx'} | ||
|
r36614 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'manifest', requires={b'repo', b'ctx'}) | ||
|
r36615 | def showmanifest(context, mapping): | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r24676 | mnode = ctx.manifestnode() | ||
|
r25736 | if mnode is None: | ||
|
r47771 | mnode = repo.nodeconstants.wdirid | ||
|
r39832 | mrev = wdirrev | ||
|
r47771 | mhex = repo.nodeconstants.wdirhex | ||
|
r39832 | else: | ||
mrev = repo.manifestlog.rev(mnode) | ||||
|
r47771 | mhex = hex(mnode) | ||
|
r43347 | mapping = context.overlaymap(mapping, {b'rev': mrev, b'node': mhex}) | ||
f = context.process(b'manifest', mapping) | ||||
|
r43346 | return templateutil.hybriditem( | ||
|
r43347 | f, None, f, lambda x: {b'rev': mrev, b'node': mhex} | ||
|
r43346 | ) | ||
|
r10055 | |||
|
r43347 | @templatekeyword(b'obsfate', requires={b'ui', b'repo', b'ctx'}) | ||
|
r36612 | def showobsfate(context, mapping): | ||
|
r34848 | # this function returns a list containing pre-formatted obsfate strings. | ||
# | ||||
# This function will be replaced by templates fragments when we will have | ||||
# the verbosity templatekw available. | ||||
|
r36612 | succsandmarkers = showsuccsandmarkers(context, mapping) | ||
|
r34848 | |||
|
r43347 | ui = context.resource(mapping, b'ui') | ||
repo = context.resource(mapping, b'repo') | ||||
|
r34848 | values = [] | ||
|
r37521 | for x in succsandmarkers.tovalue(context, mapping): | ||
|
r43346 | v = obsutil.obsfateprinter( | ||
|
r43347 | ui, repo, x[b'successors'], x[b'markers'], scmutil.formatchangeid | ||
|
r43346 | ) | ||
|
r37344 | values.append(v) | ||
|
r34848 | |||
|
r43347 | return compatlist(context, mapping, b"fate", values) | ||
|
r34848 | |||
|
r43346 | |||
|
r36611 | def shownames(context, mapping, namespace): | ||
|
r27893 | """helper method to generate a template keyword for a namespace""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r45222 | ns = repo.names.get(namespace) | ||
if ns is None: | ||||
# namespaces.addnamespace() registers new template keyword, but | ||||
# the registered namespace might not exist in the current repo. | ||||
return | ||||
|
r27893 | names = ns.names(repo, ctx.node()) | ||
|
r43346 | return compatlist( | ||
context, mapping, ns.templatename, names, plural=namespace | ||||
) | ||||
|
r27893 | |||
|
r43347 | @templatekeyword(b'namespaces', requires={b'repo', b'ctx'}) | ||
|
r36611 | def shownamespaces(context, mapping): | ||
|
r28539 | """Dict of lists. Names attached to this changeset per | ||
|
r27894 | namespace.""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r33047 | |||
namespaces = util.sortdict() | ||||
|
r43346 | |||
|
r34542 | def makensmapfn(ns): | ||
# 'name' for iterating over namespaces, templatename for local reference | ||||
|
r43347 | return lambda v: {b'name': v, ns.templatename: v} | ||
|
r33047 | |||
|
r43376 | for k, ns in pycompat.iteritems(repo.names): | ||
|
r34542 | names = ns.names(repo, ctx.node()) | ||
|
r43347 | f = _showcompatlist(context, mapping, b'name', names) | ||
|
r34542 | namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity) | ||
|
r33047 | |||
|
r43347 | f = _showcompatlist(context, mapping, b'namespace', list(namespaces)) | ||
|
r33047 | |||
def makemap(ns): | ||||
return { | ||||
|
r43347 | b'namespace': ns, | ||
b'names': namespaces[ns], | ||||
b'builtin': repo.names[ns].builtin, | ||||
b'colorname': repo.names[ns].colorname, | ||||
|
r33047 | } | ||
|
r34329 | return _hybrid(f, namespaces, makemap, pycompat.identity) | ||
|
r27894 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'negrev', requires={b'repo', b'ctx'}) | ||
|
r41871 | def shownegrev(context, mapping): | ||
"""Integer. The repository-local changeset negative revision number, | ||||
which counts in the opposite direction.""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r41875 | rev = ctx.rev() | ||
if rev is None or rev < 0: # wdir() or nullrev? | ||||
return None | ||||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
|
r41875 | return rev - len(repo) | ||
|
r41871 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'node', requires={b'ctx'}) | ||
|
r36531 | def shownode(context, mapping): | ||
|
r28539 | """String. The changeset identification hash, as a 40 hexadecimal | ||
|
r13585 | digit string. | ||
""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r10054 | return ctx.hex() | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'obsolete', requires={b'ctx'}) | ||
|
r36531 | def showobsolete(context, mapping): | ||
|
r34658 | """String. Whether the changeset is obsolete. (EXPERIMENTAL)""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r31699 | if ctx.obsolete(): | ||
|
r43347 | return b'obsolete' | ||
return b'' | ||||
|
r31699 | |||
|
r43346 | |||
|
r46480 | @templatekeyword(b'onelinesummary', requires={b'ui', b'ctx'}) | ||
def showonelinesummary(context, mapping): | ||||
"""String. A one-line summary for the ctx (not including trailing newline). | ||||
The default template be overridden in command-templates.oneline-summary.""" | ||||
# Avoid cycle: | ||||
# mercurial.cmdutil -> mercurial.templatekw -> mercurial.cmdutil | ||||
from . import cmdutil | ||||
ui = context.resource(mapping, b'ui') | ||||
ctx = context.resource(mapping, b'ctx') | ||||
return cmdutil.format_changeset_summary(ui, ctx) | ||||
|
r43347 | @templatekeyword(b'path', requires={b'fctx'}) | ||
|
r39407 | def showpath(context, mapping): | ||
"""String. Repository-absolute path of the current file. (EXPERIMENTAL)""" | ||||
|
r43347 | fctx = context.resource(mapping, b'fctx') | ||
|
r39407 | return fctx.path() | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'peerurls', requires={b'repo'}) | ||
|
r36531 | def showpeerurls(context, mapping): | ||
|
r33414 | """A dictionary of repository locations defined in the [paths] section | ||
|
r34540 | of your configuration file.""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
|
r33414 | # see commands.paths() for naming of dictionary keys | ||
|
r34539 | paths = repo.ui.paths | ||
r47806 | all_paths = urlutil.list_paths(repo.ui) | |||
urls = util.sortdict((k, p.rawloc) for k, p in all_paths) | ||||
|
r43346 | |||
|
r34539 | def makemap(k): | ||
p = paths[k] | ||||
|
r43347 | d = {b'name': k, b'url': p.rawloc} | ||
r47955 | sub_opts = util.sortdict(sorted(pycompat.iteritems(p.suboptions))) | |||
d.update(sub_opts) | ||||
path_dict = util.sortdict() | ||||
path_dict[b'url'] = p.rawloc | ||||
path_dict.update(sub_opts) | ||||
d[b'urls'] = [path_dict] | ||||
|
r34539 | return d | ||
|
r43346 | |||
r47807 | def format_one(k): | |||
return b'%s=%s' % (k, urls[k]) | ||||
return _hybrid(None, urls, makemap, format_one) | ||||
|
r33414 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b"predecessors", requires={b'repo', b'ctx'}) | ||
|
r36531 | def showpredecessors(context, mapping): | ||
|
r42629 | """Returns the list of the closest visible predecessors. (EXPERIMENTAL)""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r32879 | predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node())) | ||
|
r38325 | predecessors = pycompat.maplist(hex, predecessors) | ||
|
r32879 | |||
|
r43346 | return _hybrid( | ||
None, | ||||
predecessors, | ||||
|
r43347 | lambda x: {b'ctx': repo[x]}, | ||
|
r43346 | lambda x: scmutil.formatchangeid(repo[x]), | ||
) | ||||
|
r32879 | |||
|
r43347 | @templatekeyword(b'reporoot', requires={b'repo'}) | ||
|
r36531 | def showreporoot(context, mapping): | ||
|
r36261 | """String. The root directory of the current repository.""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
|
r36261 | return repo.root | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'size', requires={b'fctx'}) | ||
|
r39623 | def showsize(context, mapping): | ||
"""Integer. Size of the current file in bytes. (EXPERIMENTAL)""" | ||||
|
r43347 | fctx = context.resource(mapping, b'fctx') | ||
|
r39623 | return fctx.size() | ||
|
r43346 | |||
|
r39636 | # requires 'fctx' to denote {status} depends on (ctx, path) pair | ||
|
r43347 | @templatekeyword(b'status', requires={b'ctx', b'fctx', b'revcache'}) | ||
|
r39636 | def showstatus(context, mapping): | ||
"""String. Status code of the current file. (EXPERIMENTAL)""" | ||||
|
r43347 | path = templateutil.runsymbol(context, mapping, b'path') | ||
|
r39636 | path = templateutil.stringify(context, mapping, path) | ||
if not path: | ||||
return | ||||
statmap = _getfilestatusmap(context, mapping) | ||||
if path not in statmap: | ||||
statmap = _getfilestatusmap(context, mapping, listall=True) | ||||
return statmap.get(path) | ||||
|
r43346 | |||
|
r43347 | @templatekeyword(b"successorssets", requires={b'repo', b'ctx'}) | ||
|
r36531 | def showsuccessorssets(context, mapping): | ||
|
r34657 | """Returns a string of sets of successors for a changectx. Format used | ||
|
r41143 | is: [ctx1, ctx2], [ctx3] if ctx has been split into ctx1 and ctx2 | ||
|
r34658 | while also diverged into ctx3. (EXPERIMENTAL)""" | ||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r46268 | data = [] | ||
|
r33276 | |||
|
r46268 | if ctx.obsolete(): | ||
ssets = obsutil.successorssets(repo, ctx.node(), closest=True) | ||||
ssets = [[hex(n) for n in ss] for ss in ssets] | ||||
|
r33276 | |||
|
r46268 | for ss in ssets: | ||
h = _hybrid( | ||||
None, | ||||
ss, | ||||
lambda x: {b'ctx': repo[x]}, | ||||
lambda x: scmutil.formatchangeid(repo[x]), | ||||
) | ||||
data.append(h) | ||||
|
r33276 | |||
# Format the successorssets | ||||
def render(d): | ||||
|
r37292 | return templateutil.stringify(context, mapping, d) | ||
|
r33276 | |||
def gen(data): | ||||
|
r43347 | yield b"; ".join(render(d) for d in data) | ||
|
r33276 | |||
|
r43346 | return _hybrid( | ||
|
r43347 | gen(data), data, lambda x: {b'successorset': x}, pycompat.identity | ||
|
r43346 | ) | ||
|
r33276 | |||
|
r43347 | @templatekeyword(b"succsandmarkers", requires={b'repo', b'ctx'}) | ||
|
r36612 | def showsuccsandmarkers(context, mapping): | ||
|
r34657 | """Returns a list of dict for each final successor of ctx. The dict | ||
contains successors node id in "successors" keys and the list of | ||||
obs-markers from ctx to the set of successors in "markers". | ||||
|
r33913 | (EXPERIMENTAL) | ||
""" | ||||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r33913 | |||
values = obsutil.successorsandmarkers(repo, ctx) | ||||
if values is None: | ||||
values = [] | ||||
# Format successors and markers to avoid exposing binary to templates | ||||
data = [] | ||||
for i in values: | ||||
# Format successors | ||||
|
r43347 | successors = i[b'successors'] | ||
|
r33913 | |||
successors = [hex(n) for n in successors] | ||||
|
r43346 | successors = _hybrid( | ||
None, | ||||
successors, | ||||
|
r43347 | lambda x: {b'ctx': repo[x]}, | ||
|
r43346 | lambda x: scmutil.formatchangeid(repo[x]), | ||
) | ||||
|
r33913 | |||
# Format markers | ||||
finalmarkers = [] | ||||
|
r43347 | for m in i[b'markers']: | ||
|
r33913 | hexprec = hex(m[0]) | ||
hexsucs = tuple(hex(n) for n in m[1]) | ||||
hexparents = None | ||||
if m[5] is not None: | ||||
hexparents = tuple(hex(n) for n in m[5]) | ||||
newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:] | ||||
finalmarkers.append(newmarker) | ||||
|
r43347 | data.append({b'successors': successors, b'markers': finalmarkers}) | ||
|
r33913 | |||
|
r37521 | return templateutil.mappinglist(data) | ||
|
r33913 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'p1', requires={b'ctx'}) | ||
|
r40510 | def showp1(context, mapping): | ||
"""Changeset. The changeset's first parent. ``{p1.rev}`` for the revision | ||||
number, and ``{p1.node}`` for the identification hash.""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
return templateutil.mappingdict({b'ctx': ctx.p1()}, tmpl=_changeidtmpl) | ||||
|
r40510 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'p2', requires={b'ctx'}) | ||
|
r40510 | def showp2(context, mapping): | ||
"""Changeset. The changeset's second parent. ``{p2.rev}`` for the revision | ||||
number, and ``{p2.node}`` for the identification hash.""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
return templateutil.mappingdict({b'ctx': ctx.p2()}, tmpl=_changeidtmpl) | ||||
|
r40510 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'p1rev', requires={b'ctx'}) | ||
|
r36531 | def showp1rev(context, mapping): | ||
|
r28539 | """Integer. The repository-local revision number of the changeset's | ||
|
r40511 | first parent, or -1 if the changeset has no parents. (DEPRECATED)""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r17357 | return ctx.p1().rev() | ||
|
r17355 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'p2rev', requires={b'ctx'}) | ||
|
r36531 | def showp2rev(context, mapping): | ||
|
r28539 | """Integer. The repository-local revision number of the changeset's | ||
|
r40511 | second parent, or -1 if the changeset has no second parent. (DEPRECATED)""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r17357 | return ctx.p2().rev() | ||
|
r17355 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'p1node', requires={b'ctx'}) | ||
|
r36531 | def showp1node(context, mapping): | ||
|
r28539 | """String. The identification hash of the changeset's first parent, | ||
|
r17357 | as a 40 digit hexadecimal string. If the changeset has no parents, all | ||
|
r40511 | digits are 0. (DEPRECATED)""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r17357 | return ctx.p1().hex() | ||
|
r17355 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'p2node', requires={b'ctx'}) | ||
|
r36531 | def showp2node(context, mapping): | ||
|
r28539 | """String. The identification hash of the changeset's second | ||
|
r17357 | parent, as a 40 digit hexadecimal string. If the changeset has no second | ||
|
r40511 | parent, all digits are 0. (DEPRECATED)""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r17357 | return ctx.p2().hex() | ||
|
r17355 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'parents', requires={b'repo', b'ctx'}) | ||
|
r36616 | def showparents(context, mapping): | ||
|
r28539 | """List of strings. The parents of the changeset in "rev:node" | ||
|
r26434 | format. If the changeset has only one "natural" parent (the predecessor | ||
revision) nothing is shown.""" | ||||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
|
r28270 | pctxs = scmutil.meaningfulparents(repo, ctx) | ||
|
r34582 | prevs = [p.rev() for p in pctxs] | ||
|
r43346 | parents = [ | ||
|
r43347 | [(b'rev', p.rev()), (b'node', p.hex()), (b'phase', p.phasestr())] | ||
|
r43346 | for p in pctxs | ||
] | ||||
|
r43347 | f = _showcompatlist(context, mapping, b'parent', parents) | ||
|
r43346 | return _hybrid( | ||
f, | ||||
prevs, | ||||
|
r43347 | lambda x: {b'ctx': repo[x]}, | ||
|
r43346 | lambda x: scmutil.formatchangeid(repo[x]), | ||
keytype=int, | ||||
) | ||||
|
r26434 | |||
|
r43347 | @templatekeyword(b'phase', requires={b'ctx'}) | ||
|
r36531 | def showphase(context, mapping): | ||
|
r28539 | """String. The changeset phase name.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r15823 | return ctx.phasestr() | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'phaseidx', requires={b'ctx'}) | ||
|
r36531 | def showphaseidx(context, mapping): | ||
|
r34992 | """Integer. The changeset phase index. (ADVANCED)""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r15422 | return ctx.phase() | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'rev', requires={b'ctx'}) | ||
|
r36531 | def showrev(context, mapping): | ||
|
r28539 | """Integer. The repository-local changeset revision number.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r32654 | return scmutil.intrev(ctx) | ||
|
r10054 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'subrepos', requires={b'ctx'}) | ||
|
r36609 | def showsubrepos(context, mapping): | ||
|
r28539 | """List of strings. Updated subrepositories in the changeset.""" | ||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r21897 | substate = ctx.substate | ||
if not substate: | ||||
|
r43347 | return compatlist(context, mapping, b'subrepo', []) | ||
|
r41442 | psubstate = ctx.p1().substate or {} | ||
|
r21897 | subrepos = [] | ||
for sub in substate: | ||||
if sub not in psubstate or substate[sub] != psubstate[sub]: | ||||
|
r43346 | subrepos.append(sub) # modified or newly added in ctx | ||
|
r21897 | for sub in psubstate: | ||
if sub not in substate: | ||||
|
r43346 | subrepos.append(sub) # removed in ctx | ||
|
r43347 | return compatlist(context, mapping, b'subrepo', sorted(subrepos)) | ||
|
r21897 | |||
|
r43346 | |||
|
r23977 | # don't remove "showtags" definition, even though namespaces will put | ||
# a helper function for "tags" keyword into "keywords" map automatically, | ||||
# because online help text is built without namespaces initialization | ||||
|
r43347 | @templatekeyword(b'tags', requires={b'repo', b'ctx'}) | ||
|
r36611 | def showtags(context, mapping): | ||
|
r28539 | """List of strings. Any tags associated with the changeset.""" | ||
|
r43347 | return shownames(context, mapping, b'tags') | ||
|
r23977 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'termwidth', requires={b'ui'}) | ||
|
r36531 | def showtermwidth(context, mapping): | ||
|
r30088 | """Integer. The width of the current terminal.""" | ||
|
r43347 | ui = context.resource(mapping, b'ui') | ||
|
r36460 | return ui.termwidth() | ||
|
r30088 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'user', requires={b'ctx'}) | ||
|
r38983 | def showuser(context, mapping): | ||
"""String. The unmodified author of the changeset.""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r38983 | return ctx.user() | ||
|
r43346 | |||
|
r43347 | @templatekeyword(b'instabilities', requires={b'ctx'}) | ||
|
r36609 | def showinstabilities(context, mapping): | ||
|
r33675 | """List of strings. Evolution instabilities affecting the changeset. | ||
|
r30712 | (EXPERIMENTAL) | ||
""" | ||||
|
r43347 | ctx = context.resource(mapping, b'ctx') | ||
|
r43346 | return compatlist( | ||
context, | ||||
mapping, | ||||
|
r43347 | b'instability', | ||
|
r43346 | ctx.instabilities(), | ||
|
r43347 | plural=b'instabilities', | ||
|
r43346 | ) | ||
|
r30712 | |||
|
r43347 | @templatekeyword(b'verbosity', requires={b'ui'}) | ||
|
r36531 | def showverbosity(context, mapping): | ||
|
r34994 | """String. The current output verbosity in 'debug', 'quiet', 'verbose', | ||
or ''.""" | ||||
|
r43347 | ui = context.resource(mapping, b'ui') | ||
|
r35906 | # see logcmdutil.changesettemplater for priority of these flags | ||
|
r34994 | if ui.debugflag: | ||
|
r43347 | return b'debug' | ||
|
r34994 | elif ui.quiet: | ||
|
r43347 | return b'quiet' | ||
|
r34994 | elif ui.verbose: | ||
|
r43347 | return b'verbose' | ||
return b'' | ||||
|
r34994 | |||
|
r43346 | |||
|
r43347 | @templatekeyword(b'whyunstable', requires={b'repo', b'ctx'}) | ||
r37703 | def showwhyunstable(context, mapping): | |||
"""List of dicts explaining all instabilities of a changeset. | ||||
(EXPERIMENTAL) | ||||
""" | ||||
|
r43347 | repo = context.resource(mapping, b'repo') | ||
ctx = context.resource(mapping, b'ctx') | ||||
r37703 | ||||
def formatnode(ctx): | ||||
|
r43347 | return b'%s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr()) | ||
r37703 | ||||
entries = obsutil.whyunstable(repo, ctx) | ||||
for entry in entries: | ||||
|
r43347 | if entry.get(b'divergentnodes'): | ||
dnodes = entry[b'divergentnodes'] | ||||
|
r43346 | dnhybrid = _hybrid( | ||
None, | ||||
[dnode.hex() for dnode in dnodes], | ||||
|
r43347 | lambda x: {b'ctx': repo[x]}, | ||
|
r43346 | lambda x: formatnode(repo[x]), | ||
) | ||||
|
r43347 | entry[b'divergentnodes'] = dnhybrid | ||
r37703 | ||||
|
r43346 | tmpl = ( | ||
|
r43347 | b'{instability}:{if(divergentnodes, " ")}{divergentnodes} ' | ||
b'{reason} {node|short}' | ||||
|
r43346 | ) | ||
|
r43347 | return templateutil.mappinglist(entries, tmpl=tmpl, sep=b'\n') | ||
r37703 | ||||
|
r43346 | |||
|
r34993 | def loadkeyword(ui, extname, registrarobj): | ||
|
r46554 | """Load template keyword from specified registrarobj""" | ||
|
r43376 | for name, func in pycompat.iteritems(registrarobj._table): | ||
|
r34993 | keywords[name] = func | ||
|
r43346 | |||
|
r13585 | # tell hggettext to extract docstrings from these functions: | ||
|
r26436 | i18nfunctions = keywords.values() | ||