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