##// END OF EJS Templates
merge with stable
merge with stable

File last commit:

r47958:7531cc34 default
r49299:9dd151a3 merge default
Show More
templatekw.py
1017 lines | 33.7 KiB | text/x-python | PythonLexer
Patrick Mezard
cmdutil: replace showlist() closure with a function
r10053 # templatekw.py - common changeset template keywords
#
Raphaël Gomès
contributor: change mentions of mpm to olivia...
r47575 # Copyright 2005-2009 Olivia Mackall <olivia@selenic.com>
Patrick Mezard
cmdutil: replace showlist() closure with a function
r10053 #
# This software may be used and distributed according to the terms of the
Matt Mackall
Merge with stable
r10264 # GNU General Public License version 2 or any later version.
Patrick Mezard
cmdutil: replace showlist() closure with a function
r10053
Gregory Szorc
templatekw: use absolute_import
r25984 from __future__ import absolute_import
Yuya Nishihara
templater: provide loop counter as "index" keyword...
r31807 from .i18n import _
Yuya Nishihara
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)...
r32656 from .node import (
hex,
Yuya Nishihara
log: fill in pseudo rev and node as wdir() manifest identifiers...
r39832 wdirrev,
Yuya Nishihara
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)...
r32656 )
Gregory Szorc
templatekw: use absolute_import
r25984 from . import (
Yuya Nishihara
diffutil: move the module out of utils package...
r38607 diffutil,
Yuya Nishihara
templatekw: workaround for utf-8 round-trip of {desc}...
r28239 encoding,
Gregory Szorc
templatekw: use absolute_import
r25984 error,
hbisect,
Yuya Nishihara
log: translate column labels at once (issue5750)...
r35213 i18n,
Boris Feld
template: add predecessors template...
r32879 obsutil,
Gregory Szorc
templatekw: use absolute_import
r25984 patch,
Pulkit Goyal
py3: convert keys of kwargs in template keywords functions to bytes...
r32972 pycompat,
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 registrar,
Gregory Szorc
templatekw: use absolute_import
r25984 scmutil,
Yuya Nishihara
templater: move hybrid class and functions to templateutil module...
r36939 templateutil,
Gregory Szorc
templatekw: use absolute_import
r25984 util,
)
template: use `list_paths` in `peerurls`...
r47806 from .utils import (
stringutil,
urlutil,
)
Patrick Mezard
cmdutil: replace showlist() closure with a function
r10053
Yuya Nishihara
templater: move hybrid class and functions to templateutil module...
r36939 _hybrid = templateutil.hybrid
hybriddict = templateutil.hybriddict
hybridlist = templateutil.hybridlist
compatdict = templateutil.compatdict
compatlist = templateutil.compatlist
Yuya Nishihara
templater: use template context to render old-style list template...
r37086 _showcompatlist = templateutil._showcompatlist
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 def getlatesttags(context, mapping, pattern=None):
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057 '''return date, distance and name for the latest tag of rev'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
cache = context.resource(mapping, b'cache')
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cachename = b'latesttags'
Matt Harbison
templatekw: allow getlatesttags() to match a specific tag pattern...
r26482 if pattern is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cachename += b'-' + pattern
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 match = stringutil.stringmatcher(pattern)[2]
Matt Harbison
templatekw: allow getlatesttags() to match a specific tag pattern...
r26482 else:
match = util.always
if cachename not in cache:
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057 # Cache mapping from rev to a tuple with tag date, tag
# distance and tag name
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cache[cachename] = {-1: (0, 0, [b'null'])}
Matt Harbison
templatekw: allow getlatesttags() to match a specific tag pattern...
r26482 latesttags = cache[cachename]
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057
rev = ctx.rev()
todo = [rev]
while todo:
rev = todo.pop()
if rev in latesttags:
continue
ctx = repo[rev]
Augie Fackler
formatting: blacken the codebase...
r43346 tags = [
t
for t in ctx.tags()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if (repo.tagtype(t) and repo.tagtype(t) != b'local' and match(t))
Augie Fackler
formatting: blacken the codebase...
r43346 ]
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057 if tags:
Matt Harbison
templatekw: use a list of tags in getlatesttags() instead of joining them...
r25700 latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057 continue
try:
Martin von Zweigbergk
templatekw: choose {latesttag} by len(changes), not date (issue5659)...
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
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
templatekw: choose {latesttag} by len(changes), not date (issue5659)...
r33866 def key(x):
Yuya Nishihara
templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)...
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
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changes = repo.revs(b'only(%ld, %s)', prevs, tag)
Yuya Nishihara
templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)...
r41336 changessincetag = len(changes) + 1
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changes = repo.revs(b'only(%d, %s)', ctx.rev(), tag)
Yuya Nishihara
templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)...
r41336 changessincetag = len(changes)
Martin von Zweigbergk
templatekw: choose {latesttag} by len(changes), not date (issue5659)...
r33866 # Smallest number of changes since tag wins. Date is
# used as tiebreaker.
return [-changessincetag, x[0]]
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
templatekw: choose {latesttag} by len(changes), not date (issue5659)...
r33866 pdate, pdist, ptag = max(ptags, key=key)
else:
pdate, pdist, ptag = ptags[0]
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
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
formatting: blacken the codebase...
r43346
Yuya Nishihara
log: translate column labels at once (issue5750)...
r35213 def getlogcolumns():
"""Return a dict of log column labels"""
_ = pycompat.identity # temporarily disable gettext
# i18n: column positioning for "hg log"
Augie Fackler
formatting: blacken the codebase...
r43346 columns = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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
formatting: blacken the codebase...
r43346 )
return dict(
zip(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [s.split(b':', 1)[0] for s in columns.splitlines()],
Augie Fackler
formatting: blacken the codebase...
r43346 i18n._(columns).splitlines(True),
)
)
Yuya Nishihara
log: translate column labels at once (issue5750)...
r35213
Yuya Nishihara
templatekw: extract internal "{rev}:{node|formatnode}" template to constant...
r40508 # basic internal templates
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _changeidtmpl = b'{rev}:{node|formatnode}'
Yuya Nishihara
templatekw: extract internal "{rev}:{node|formatnode}" template to constant...
r40508
Yuya Nishihara
templatekw: move defaulttmpl constant from changeset_templater...
r31171 # default templates internally used for rendering of lists
defaulttempl = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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
templatekw: move defaulttmpl constant from changeset_templater...
r31171 }
# filecopy is preserved for compatibility reasons
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 defaulttempl[b'filecopy'] = defaulttempl[b'file_copy']
Yuya Nishihara
templatekw: move defaulttmpl constant from changeset_templater...
r31171
Yuya Nishihara
templatekw: add 'requires' flag to switch to exception-safe interface...
r36463 # keywords are callables (see registrar.templatekeyword for details)
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 keywords = {}
templatekeyword = registrar.templatekeyword(keywords)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'author', requires={b'ctx'})
Yuya Nishihara
templatekw: add 'requires' flag to switch to exception-safe interface...
r36463 def showauthor(context, mapping):
Yuya Nishihara
templatekw: copy {author} to {user} and document {author} as an alias...
r38983 """Alias for ``{user}``"""
return showuser(context, mapping)
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'bisect', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showbisect(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The changeset bisection status."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
"Yann E. MORIN"
templates: add 'bisect' keyword to return a cset's bisect status...
r15155 return hbisect.label(repo, ctx.node())
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'branch', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showbranch(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The name of the branch on which the changeset was
Patrick Mezard
templates: generate keyword help dynamically
r13585 committed.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 return ctx.branch()
Eric Eisner
template: add showbranch template for {branch}...
r13156
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'branches', requires={b'ctx'})
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 def showbranches(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. The name of the branch on which the
Patrick Mezard
templates: generate keyword help dynamically
r13585 changeset was committed. Will be empty if the branch name was
Yuya Nishihara
templatekw: hide help of "branches" by DEPRECATED marker...
r26437 default. (DEPRECATED)
Patrick Mezard
templates: generate keyword help dynamically
r13585 """
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 branch = ctx.branch()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if branch != b'default':
Augie Fackler
formatting: blacken the codebase...
r43346 return compatlist(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 context, mapping, b'branch', [branch], plural=b'branches'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return compatlist(context, mapping, b'branch', [], plural=b'branches')
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'bookmarks', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch remainder of _showlist template keywords to new API
r36616 def showbookmarks(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Any bookmarks associated with the
Ryan McElroy
templatekw: introduce active subkeyword from bookmarks keyword...
r25348 changeset. Also sets 'active', the name of the active bookmark.
Patrick Mezard
templates: document missing keywords or filters...
r13592 """
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: switch remainder of _showlist template keywords to new API
r36616 bookmarks = ctx.bookmarks()
Ryan McElroy
templatekw: introduce active subkeyword from bookmarks keyword...
r25348 active = repo._activebookmark
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 makemap = lambda v: {b'bookmark': v, b'active': active, b'current': active}
f = _showcompatlist(context, mapping, b'bookmark', bookmarks)
Yuya Nishihara
templatekw: just pass underlying value (or key) to joinfmt() function...
r34329 return _hybrid(f, bookmarks, makemap, pycompat.identity)
David Soria Parra
templater: add bookmarks to templates and default output...
r13386
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'children', requires={b'ctx'})
Yuya Nishihara
templatekw: add compatlist() as a replacement for showlist()...
r36538 def showchildren(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. The children of the changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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
templates: 'children' keyword...
r11655
Augie Fackler
formatting: blacken the codebase...
r43346
Ryan McElroy
templatekw: introduce activebookmark keyword...
r25013 # Deprecated, but kept alive for help generation a purpose.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'currentbookmark', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showcurrentbookmark(context, mapping):
Yuya Nishihara
help: fix formatting of template keywords...
r34657 """String. The active bookmark, if it is associated with the changeset.
(DEPRECATED)"""
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 return showactivebookmark(context, mapping)
Ryan McElroy
templatekw: introduce activebookmark keyword...
r25013
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'activebookmark', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showactivebookmark(context, mapping):
Yuya Nishihara
help: fix formatting of template keywords...
r34657 """String. The active bookmark, if it is associated with the changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 active = repo._activebookmark
if active and active in ctx.bookmarks():
Ryan McElroy
templatekw: display active bookmark more consistently (issue4552) (BC)...
r25387 return active
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''
FUJIWARA Katsunori
templatekw: add 'currentbookmark' keyword to show current bookmark easily...
r21896
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'date', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showdate(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Date information. The date when the changeset was committed."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templater: restore the original string format of {date}...
r38318 # the default string format is '<float(unixtime)><tzoffset>' because
# python-hglib splits date at decimal separator.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return templateutil.date(ctx.date(), showfmt=b'%d.0%d')
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'desc', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showdescription(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The text of the changeset description."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: workaround for utf-8 round-trip of {desc}...
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
encoding: introduce tagging type for non-lossy non-ASCII string...
r37966 elif isinstance(s, encoding.safelocalstr):
return encoding.safelocalstr(s.strip())
Yuya Nishihara
templatekw: workaround for utf-8 round-trip of {desc}...
r28239 else:
return s.strip()
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'diffstat', requires={b'ui', b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showdiffstat(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. Statistics of changes with the following format:
Patrick Mezard
templates: generate keyword help dynamically
r13585 "modified files: +added/-removed lines"
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui = context.resource(mapping, b'ui')
ctx = context.resource(mapping, b'ctx')
diffopts = diffutil.diffallopts(ui, {b'noprefix': False})
Boris Feld
template: directly instantiate diff options for diffstat
r38583 diff = ctx.diff(opts=diffopts)
Boris Feld
context: explicitly take diffopts in `context.diff` (API)...
r38538 stats = patch.diffstatdata(util.iterlines(diff))
Steven Brown
patch: restore the previous output of 'diff --stat'...
r14437 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'%d: +%d/-%d' % (len(stats), adds, removes)
Patrick Mezard
cmdutil: extract repo dependent closures in templatekw
r10055
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'envvars', requires={b'ui'})
Yuya Nishihara
templatekw: add compatdict() as a replacement for showdict()...
r36537 def showenvvars(context, mapping):
Matt Harbison
templater: add '{envvars}' to access environment variables...
r30833 """A dictionary of environment variables. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui = context.resource(mapping, b'ui')
Yuya Nishihara
templatekw: minimize resource dependency of {envvars} and {termwidth}...
r36460 env = ui.exportableenviron()
Matt Harbison
templater: add '{envvars}' to access environment variables...
r30833 env = util.sortdict((k, env[k]) for k in sorted(env))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return compatdict(context, mapping, b'envvar', env, plural=b'envvars')
Matt Harbison
templater: add '{envvars}' to access environment variables...
r30833
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'extras', requires={b'ctx'})
Yuya Nishihara
templatekw: switch remainder of _showlist template keywords to new API
r36616 def showextras(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of dicts with key, value entries of the 'extras'
Matthew Turk
help: document about {extras} template keyword...
r20015 field of this changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: switch remainder of _showlist template keywords to new API
r36616 extras = ctx.extra()
Yuya Nishihara
templatekw: convert list of key/value pairs to sortdict...
r24237 extras = util.sortdict((k, extras[k]) for k in sorted(extras))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 makemap = lambda k: {b'key': k, b'value': extras[k]}
Yuya Nishihara
templatekw: give name to lambda that constructs variables map of templater...
r24238 c = [makemap(k) for k in extras]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = _showcompatlist(context, mapping, b'extra', c, plural=b'extras')
Augie Fackler
formatting: blacken the codebase...
r43346 return _hybrid(
f,
extras,
makemap,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lambda k: b'%s=%s' % (k, stringutil.escapestr(extras[k])),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Yuya Nishihara
templatekw: add option to include ignored/clean/unknown files in cache...
r39635 def _getfilestatus(context, mapping, listall=False):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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
formatting: blacken the codebase...
r43346 stat = ctx.p1().status(
ctx, listignored=listall, listclean=listall, listunknown=listall
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revcache[b'filestatus'] = stat
revcache[b'filestatusall'] = listall
return revcache[b'filestatus']
Yuya Nishihara
templatekw: extract function that computes and caches file status
r39633
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: add experimental {status} keyword...
r39636 def _getfilestatusmap(context, mapping, listall=False):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revcache = context.resource(mapping, b'revcache')
if b'filestatusmap' not in revcache or revcache[b'filestatusall'] < listall:
Yuya Nishihara
templatekw: add experimental {status} keyword...
r39636 stat = _getfilestatus(context, mapping, listall=listall)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 revcache[b'filestatusmap'] = statmap = {}
for char, files in zip(pycompat.iterbytestr(b'MAR!?IC'), stat):
Yuya Nishihara
templatekw: add experimental {status} keyword...
r39636 statmap.update((f, char) for f in files)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return revcache[b'filestatusmap'] # {path: statchar}
Yuya Nishihara
templatekw: add experimental {status} keyword...
r39636
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(
b'file_copies', requires={b'repo', b'ctx', b'cache', b'revcache'}
)
Yuya Nishihara
templatekw: switch showdict template keywords to new API
r36608 def showfilecopies(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Files copied in this changeset with
Patrick Mezard
templates: generate keyword help dynamically
r13585 their sources.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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
templatekw: change {file_copies} behaviour, add {file_copies_switch}...
r10060 if copies is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'getcopies' not in cache:
cache[b'getcopies'] = scmutil.getcopiesfn(repo)
getcopies = cache[b'getcopies']
Martin von Zweigbergk
copies: create helper for getting all copies for changeset...
r42703 copies = getcopies(ctx)
Augie Fackler
formatting: blacken the codebase...
r43346 return templateutil.compatfilecopiesdict(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 context, mapping, b'file_copy', copies
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
templatekw: change {file_copies} behaviour, add {file_copies_switch}...
r10060
# showfilecopiesswitch() displays file copies only if copy records are
# provided before calling the templater, usually with a --copies
# command line switch.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'file_copies_switch', requires={b'revcache'})
Yuya Nishihara
templatekw: switch showdict template keywords to new API
r36608 def showfilecopiesswitch(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Like "file_copies" but displayed
Patrick Mezard
templates: generate keyword help dynamically
r13585 only if the --copied switch is set.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 copies = context.resource(mapping, b'revcache').get(b'copies') or []
Augie Fackler
formatting: blacken the codebase...
r43346 return templateutil.compatfilecopiesdict(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 context, mapping, b'file_copy', copies
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
cmdutil: extract file copies closure into templatekw
r10058
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'file_adds', requires={b'ctx', b'revcache'})
Martin von Zweigbergk
templatekw: move showfileadds() close to showfile{mods,dels}()...
r42563 def showfileadds(context, mapping):
"""List of strings. Files added by this changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Augie Fackler
formatting: blacken the codebase...
r43346 return templateutil.compatfileslist(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 context, mapping, b'file_add', ctx.filesadded()
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
templatekw: move showfileadds() close to showfile{mods,dels}()...
r42563
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'file_dels', requires={b'ctx', b'revcache'})
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 def showfiledels(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Files removed by this changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Augie Fackler
formatting: blacken the codebase...
r43346 return templateutil.compatfileslist(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 context, mapping, b'file_del', ctx.filesremoved()
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
cmdutil: extract file changes closures into templatekw
r10056
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'file_mods', requires={b'ctx', b'revcache'})
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 def showfilemods(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Files modified by this changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Augie Fackler
formatting: blacken the codebase...
r43346 return templateutil.compatfileslist(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 context, mapping, b'file_mod', ctx.filesmodified()
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
cmdutil: extract file changes closures into templatekw
r10056
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'files', requires={b'ctx'})
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 def showfiles(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. All files modified, added, or removed by this
Patrick Mezard
templates: generate keyword help dynamically
r13585 changeset.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
return templateutil.compatfileslist(context, mapping, b'file', ctx.files())
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 @templatekeyword(b'graphnode', requires={b'repo', b'ctx', b'cache'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showgraphnode(context, mapping):
Yuya Nishihara
help: fix formatting of template keywords...
r34657 """String. The character representing the changeset node in an ASCII
revision graph."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 cache = context.resource(mapping, b'cache')
return getgraphnode(repo, ctx, cache)
Yuya Nishihara
templatekw: extract non-templatekw function as getgraphnode()...
r36530
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 def getgraphnode(repo, ctx, cache):
return getgraphnodecurrent(repo, ctx, cache) or getgraphnodesymbol(ctx)
av6
templates: split getgraphnode() body into two functions...
r37927
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 def getgraphnodecurrent(repo, ctx, cache):
Yuya Nishihara
templatekw: avoid slow creation of changectx objects in showgraphnode()...
r27215 wpnodes = repo.dirstate.parents()
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if wpnodes[1] == repo.nullid:
Yuya Nishihara
templatekw: avoid slow creation of changectx objects in showgraphnode()...
r27215 wpnodes = wpnodes[:1]
Yuya Nishihara
graphlog: extract "graphnode" template keyword that represents node symbol...
r27214 if ctx.node() in wpnodes:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'@'
av6
templates: split getgraphnode() body into two functions...
r37927 else:
Yuya Nishihara
templatekw: cache mergestate even if merge is not ongoing...
r45206 merge_nodes = cache.get(b'merge_nodes')
if merge_nodes is None:
Augie Fackler
mergestate: split out merge state handling code from main merge module...
r45383 from . import mergestate as mergestatemod
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819
Augie Fackler
mergestate: split out merge state handling code from main merge module...
r45383 mergestate = mergestatemod.mergestate.read(repo)
Martin von Zweigbergk
graphlog: use '%' only if there are *unresolved* conflicts...
r46020 if mergestate.unresolvedcount():
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 merge_nodes = (mergestate.local, mergestate.other)
Yuya Nishihara
templatekw: cache mergestate even if merge is not ongoing...
r45206 else:
merge_nodes = ()
Martin von Zweigbergk
graphlog: use '%' for other context in merge conflict...
r44819 cache[b'merge_nodes'] = merge_nodes
if ctx.node() in merge_nodes:
return b'%'
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''
av6
templates: split getgraphnode() body into two functions...
r37927
Augie Fackler
formatting: blacken the codebase...
r43346
av6
templates: split getgraphnode() body into two functions...
r37927 def getgraphnodesymbol(ctx):
if ctx.obsolete():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'x'
av6
graphlog: add another graph node type, unstable, using character "*" (BC)
r35524 elif ctx.isunstable():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'*'
Yuya Nishihara
graphlog: extract "graphnode" template keyword that represents node symbol...
r27214 elif ctx.closesbranch():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'_'
Yuya Nishihara
graphlog: extract "graphnode" template keyword that represents node symbol...
r27214 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'o'
Yuya Nishihara
graphlog: extract "graphnode" template keyword that represents node symbol...
r27214
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'graphwidth', requires=())
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showgraphwidth(context, mapping):
Danny Hooper
log: add a "graphwidth" template variable...
r33860 """Integer. The width of the graph drawn by 'log --graph' or zero."""
Yuya Nishihara
templatekw: simply override {graphwidth} function by mapping variable
r36459 # just hosts documentation; should be overridden by template mapping
return 0
Danny Hooper
log: add a "graphwidth" template variable...
r33860
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'index', requires=())
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showindex(context, mapping):
Yuya Nishihara
templater: provide loop counter as "index" keyword...
r31807 """Integer. The current iteration of the loop. (0 indexed)"""
# just hosts documentation; should be overridden by template mapping
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"can't use index in this context"))
Yuya Nishihara
templater: provide loop counter as "index" keyword...
r31807
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'latesttag', requires={b'repo', b'ctx', b'cache'})
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 def showlatesttag(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. The global tags on the most recent globally
Matt Harbison
templatekw: clarify the result of {latesttag} when no tag exists...
r31850 tagged ancestor of this changeset. If no such tags exist, the list
consists of the single string "null".
Patrick Mezard
templates: generate keyword help dynamically
r13585 """
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 return showlatesttags(context, mapping, None)
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 def showlatesttags(context, mapping, pattern):
Matt Harbison
templatekw: introduce showlatesttags() to handle {latesttag} keywords...
r26484 """helper method for the latesttag keyword and function"""
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 latesttags = getlatesttags(context, mapping, pattern)
Matt Harbison
templatekw: introduce showlatesttags() to handle {latesttag} keywords...
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
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'changes': _showchangessincetag,
b'distance': latesttags[1],
b'latesttag': v, # BC with {latesttag % '{latesttag}'}
b'tag': v,
Matt Harbison
templatekw: introduce showlatesttags() to handle {latesttag} keywords...
r26484 }
tags = latesttags[2]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = _showcompatlist(context, mapping, b'latesttag', tags, separator=b':')
Yuya Nishihara
templatekw: just pass underlying value (or key) to joinfmt() function...
r34329 return _hybrid(f, tags, makemap, pycompat.identity)
Matt Harbison
templatekw: introduce showlatesttags() to handle {latesttag} keywords...
r26484
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'latesttagdistance', requires={b'repo', b'ctx', b'cache'})
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 def showlatesttagdistance(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Integer. Longest path to the latest tag."""
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 return getlatesttags(context, mapping)[1]
Patrick Mezard
cmdutil: extract latest tags closures in templatekw
r10057
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'changessincelatesttag', requires={b'repo', b'ctx', b'cache'})
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 def showchangessincelatesttag(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Integer. All ancestors not in the latest tag."""
Yuya Nishihara
templater: factor out function to create mapping dict for nested evaluation...
r37092 tag = getlatesttags(context, mapping)[2][0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mapping = context.overlaymap(mapping, {b'tag': tag})
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 return _showchangessincetag(context, mapping)
Matt Harbison
templatekw: factor out the changessincetag calculation to a private method...
r26483
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 def _showchangessincetag(context, mapping):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Matt Harbison
templatekw: introduce the changessincelatesttag keyword...
r25724 offset = 0
revs = [ctx.rev()]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 tag = context.symbol(mapping, b'tag')
Matt Harbison
templatekw: introduce the changessincelatesttag keyword...
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
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return len(repo.revs(b'only(%ld, %s)', revs, tag)) + offset
Matt Harbison
templatekw: introduce the changessincelatesttag keyword...
r25724
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614 # teach templater latesttags.changes is switched to (context, mapping) API
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _showchangessincetag._requires = {b'repo', b'ctx'}
Yuya Nishihara
templatekw: switch latesttags template keywords to new API
r36614
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'manifest', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch manifest template keyword to new API
r36615 def showmanifest(context, mapping):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: have {manifest} use ctx.manifestnode() for consistency...
r24676 mnode = ctx.manifestnode()
Yuya Nishihara
templatekw: apply manifest template only if ctx.manifestnode() exists...
r25736 if mnode is None:
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 mnode = repo.nodeconstants.wdirid
Yuya Nishihara
log: fill in pseudo rev and node as wdir() manifest identifiers...
r39832 mrev = wdirrev
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 mhex = repo.nodeconstants.wdirhex
Yuya Nishihara
log: fill in pseudo rev and node as wdir() manifest identifiers...
r39832 else:
mrev = repo.manifestlog.rev(mnode)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 mhex = hex(mnode)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mapping = context.overlaymap(mapping, {b'rev': mrev, b'node': mhex})
f = context.process(b'manifest', mapping)
Augie Fackler
formatting: blacken the codebase...
r43346 return templateutil.hybriditem(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f, None, f, lambda x: {b'rev': mrev, b'node': mhex}
Augie Fackler
formatting: blacken the codebase...
r43346 )
Patrick Mezard
cmdutil: extract repo dependent closures in templatekw
r10055
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'obsfate', requires={b'ui', b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch obsfate-related template keywords to new API
r36612 def showobsfate(context, mapping):
Boris Feld
templatekw: introduce obsfate keyword...
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
templatekw: switch obsfate-related template keywords to new API
r36612 succsandmarkers = showsuccsandmarkers(context, mapping)
Boris Feld
templatekw: introduce obsfate keyword...
r34848
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui = context.resource(mapping, b'ui')
repo = context.resource(mapping, b'repo')
Boris Feld
templatekw: introduce obsfate keyword...
r34848 values = []
Yuya Nishihara
templatekw: fix return type of {succsandmarkers} (BC)...
r37521 for x in succsandmarkers.tovalue(context, mapping):
Augie Fackler
formatting: blacken the codebase...
r43346 v = obsutil.obsfateprinter(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui, repo, x[b'successors'], x[b'markers'], scmutil.formatchangeid
Augie Fackler
formatting: blacken the codebase...
r43346 )
Yuya Nishihara
obsutil: make obsfateprinter() less dependent on templater...
r37344 values.append(v)
Boris Feld
templatekw: introduce obsfate keyword...
r34848
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return compatlist(context, mapping, b"fate", values)
Boris Feld
templatekw: introduce obsfate keyword...
r34848
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: switch namespace template keywords to new API
r36611 def shownames(context, mapping, namespace):
Yuya Nishihara
templatekw: move shownames() helper to be sorted alphabetically...
r27893 """helper method to generate a template keyword for a namespace"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: fix shownames() to check if namespace exists in repo (issue6301)...
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
templatekw: move shownames() helper to be sorted alphabetically...
r27893 names = ns.names(repo, ctx.node())
Augie Fackler
formatting: blacken the codebase...
r43346 return compatlist(
context, mapping, ns.templatename, names, plural=namespace
)
Yuya Nishihara
templatekw: move shownames() helper to be sorted alphabetically...
r27893
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'namespaces', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch namespace template keywords to new API
r36611 def shownamespaces(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Dict of lists. Names attached to this changeset per
Yuya Nishihara
templatekw: add {namespaces} keyword...
r27894 namespace."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Gregory Szorc
templatekw: expose color name in {namespaces} entries...
r33047
namespaces = util.sortdict()
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: allow accessing to nested namespace item by its template name...
r34542 def makensmapfn(ns):
# 'name' for iterating over namespaces, templatename for local reference
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return lambda v: {b'name': v, ns.templatename: v}
Gregory Szorc
templatekw: expose color name in {namespaces} entries...
r33047
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for k, ns in pycompat.iteritems(repo.names):
Yuya Nishihara
templatekw: allow accessing to nested namespace item by its template name...
r34542 names = ns.names(repo, ctx.node())
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = _showcompatlist(context, mapping, b'name', names)
Yuya Nishihara
templatekw: allow accessing to nested namespace item by its template name...
r34542 namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
Gregory Szorc
templatekw: expose color name in {namespaces} entries...
r33047
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = _showcompatlist(context, mapping, b'namespace', list(namespaces))
Gregory Szorc
templatekw: expose color name in {namespaces} entries...
r33047
def makemap(ns):
return {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'namespace': ns,
b'names': namespaces[ns],
b'builtin': repo.names[ns].builtin,
b'colorname': repo.names[ns].colorname,
Gregory Szorc
templatekw: expose color name in {namespaces} entries...
r33047 }
Yuya Nishihara
templatekw: just pass underlying value (or key) to joinfmt() function...
r34329 return _hybrid(f, namespaces, makemap, pycompat.identity)
Yuya Nishihara
templatekw: add {namespaces} keyword...
r27894
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'negrev', requires={b'repo', b'ctx'})
Jordi Gutiérrez Hermoso
templatekw: add a {negrev} keyword...
r41871 def shownegrev(context, mapping):
"""Integer. The repository-local changeset negative revision number,
which counts in the opposite direction."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Jordi Gutiérrez Hermoso
templatekw: make negrev return empty for wdir() and nullrev...
r41875 rev = ctx.rev()
if rev is None or rev < 0: # wdir() or nullrev?
return None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
Jordi Gutiérrez Hermoso
templatekw: make negrev return empty for wdir() and nullrev...
r41875 return rev - len(repo)
Jordi Gutiérrez Hermoso
templatekw: add a {negrev} keyword...
r41871
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'node', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def shownode(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The changeset identification hash, as a 40 hexadecimal
Patrick Mezard
templates: generate keyword help dynamically
r13585 digit string.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054 return ctx.hex()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'obsolete', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showobsolete(context, mapping):
Yuya Nishihara
help: hide template keywords of obsolescence as they are still experimental
r34658 """String. Whether the changeset is obsolete. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Denis Laxalde
templatekw: add an "obsolete" keyword...
r31699 if ctx.obsolete():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'obsolete'
return b''
Denis Laxalde
templatekw: add an "obsolete" keyword...
r31699
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
templates: define a {onelinesummary} keyword...
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)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'path', requires={b'fctx'})
Yuya Nishihara
templatekw: add {path} keyword to host documentation...
r39407 def showpath(context, mapping):
"""String. Repository-absolute path of the current file. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fctx = context.resource(mapping, b'fctx')
Yuya Nishihara
templatekw: add {path} keyword to host documentation...
r39407 return fctx.path()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'peerurls', requires={b'repo'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showpeerurls(context, mapping):
Yuya Nishihara
templatekw: export ui.paths as {peerpaths}...
r33414 """A dictionary of repository locations defined in the [paths] section
Yuya Nishihara
templatekw: rename peerpaths to peerurls per naming convention (BC)...
r34540 of your configuration file."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
Yuya Nishihara
templatekw: export ui.paths as {peerpaths}...
r33414 # see commands.paths() for naming of dictionary keys
Yuya Nishihara
templatekw: make experimental {peerpaths} return a single-level dict (BC)...
r34539 paths = repo.ui.paths
template: use `list_paths` in `peerurls`...
r47806 all_paths = urlutil.list_paths(repo.ui)
urls = util.sortdict((k, p.rawloc) for k, p in all_paths)
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: make experimental {peerpaths} return a single-level dict (BC)...
r34539 def makemap(k):
urlutil: make `paths` class old list of `path`...
r47958 ps = paths[k]
d = {b'name': k}
if len(ps) == 1:
d[b'url'] = ps[0].rawloc
sub_opts = pycompat.iteritems(ps[0].suboptions)
sub_opts = util.sortdict(sorted(sub_opts))
d.update(sub_opts)
template: add a `paths` field to all entry in peerurls...
r47955 path_dict = util.sortdict()
urlutil: make `paths` class old list of `path`...
r47958 for p in ps:
sub_opts = util.sortdict(sorted(pycompat.iteritems(p.suboptions)))
path_dict[b'url'] = p.rawloc
path_dict.update(sub_opts)
d[b'urls'] = [path_dict]
Yuya Nishihara
templatekw: make experimental {peerpaths} return a single-level dict (BC)...
r34539 return d
Augie Fackler
formatting: blacken the codebase...
r43346
template: make an explicit closure for formatting entry in peerurls...
r47807 def format_one(k):
return b'%s=%s' % (k, urls[k])
return _hybrid(None, urls, makemap, format_one)
Yuya Nishihara
templatekw: export ui.paths as {peerpaths}...
r33414
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b"predecessors", requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showpredecessors(context, mapping):
Joerg Sonnenberger
doc: fix description of "predecessors" to match reality...
r42629 """Returns the list of the closest visible predecessors. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Boris Feld
template: add predecessors template...
r32879 predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
Yuya Nishihara
py3: fix map() use in templatekw.showpredecessors()...
r38325 predecessors = pycompat.maplist(hex, predecessors)
Boris Feld
template: add predecessors template...
r32879
Augie Fackler
formatting: blacken the codebase...
r43346 return _hybrid(
None,
predecessors,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lambda x: {b'ctx': repo[x]},
Augie Fackler
formatting: blacken the codebase...
r43346 lambda x: scmutil.formatchangeid(repo[x]),
)
Boris Feld
template: add predecessors template...
r32879
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'reporoot', requires={b'repo'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showreporoot(context, mapping):
Yuya Nishihara
templatekw: add {reporoot} keyword...
r36261 """String. The root directory of the current repository."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
Yuya Nishihara
templatekw: add {reporoot} keyword...
r36261 return repo.root
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'size', requires={b'fctx'})
Yuya Nishihara
templatekw: add {size} keyword as an example of fctx-based keyword...
r39623 def showsize(context, mapping):
"""Integer. Size of the current file in bytes. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fctx = context.resource(mapping, b'fctx')
Yuya Nishihara
templatekw: add {size} keyword as an example of fctx-based keyword...
r39623 return fctx.size()
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: add experimental {status} keyword...
r39636 # requires 'fctx' to denote {status} depends on (ctx, path) pair
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'status', requires={b'ctx', b'fctx', b'revcache'})
Yuya Nishihara
templatekw: add experimental {status} keyword...
r39636 def showstatus(context, mapping):
"""String. Status code of the current file. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 path = templateutil.runsymbol(context, mapping, b'path')
Yuya Nishihara
templatekw: add experimental {status} keyword...
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
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b"successorssets", requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showsuccessorssets(context, mapping):
Yuya Nishihara
help: fix formatting of template keywords...
r34657 """Returns a string of sets of successors for a changectx. Format used
Matt Harbison
templatekw: fix documentation typos
r41143 is: [ctx1, ctx2], [ctx3] if ctx has been split into ctx1 and ctx2
Yuya Nishihara
help: hide template keywords of obsolescence as they are still experimental
r34658 while also diverged into ctx3. (EXPERIMENTAL)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Aay Jay Chan
templatekw: make {successorssets} always return a list (issue6342)...
r46268 data = []
Boris Feld
template: add successors template...
r33276
Aay Jay Chan
templatekw: make {successorssets} always return a list (issue6342)...
r46268 if ctx.obsolete():
ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
ssets = [[hex(n) for n in ss] for ss in ssets]
Boris Feld
template: add successors template...
r33276
Aay Jay Chan
templatekw: make {successorssets} always return a list (issue6342)...
r46268 for ss in ssets:
h = _hybrid(
None,
ss,
lambda x: {b'ctx': repo[x]},
lambda x: scmutil.formatchangeid(repo[x]),
)
data.append(h)
Boris Feld
template: add successors template...
r33276
# Format the successorssets
def render(d):
Yuya Nishihara
templatekw: do not directly call .gen
r37292 return templateutil.stringify(context, mapping, d)
Boris Feld
template: add successors template...
r33276
def gen(data):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b"; ".join(render(d) for d in data)
Boris Feld
template: add successors template...
r33276
Augie Fackler
formatting: blacken the codebase...
r43346 return _hybrid(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 gen(data), data, lambda x: {b'successorset': x}, pycompat.identity
Augie Fackler
formatting: blacken the codebase...
r43346 )
Boris Feld
template: add successors template...
r33276
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b"succsandmarkers", requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch obsfate-related template keywords to new API
r36612 def showsuccsandmarkers(context, mapping):
Yuya Nishihara
help: fix formatting of template keywords...
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
template: add minimal obsfate template function...
r33913 (EXPERIMENTAL)
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Boris Feld
template: add minimal obsfate template function...
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
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 successors = i[b'successors']
Boris Feld
template: add minimal obsfate template function...
r33913
successors = [hex(n) for n in successors]
Augie Fackler
formatting: blacken the codebase...
r43346 successors = _hybrid(
None,
successors,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lambda x: {b'ctx': repo[x]},
Augie Fackler
formatting: blacken the codebase...
r43346 lambda x: scmutil.formatchangeid(repo[x]),
)
Boris Feld
template: add minimal obsfate template function...
r33913
# Format markers
finalmarkers = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for m in i[b'markers']:
Boris Feld
template: add minimal obsfate template function...
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
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 data.append({b'successors': successors, b'markers': finalmarkers})
Boris Feld
template: add minimal obsfate template function...
r33913
Yuya Nishihara
templatekw: fix return type of {succsandmarkers} (BC)...
r37521 return templateutil.mappinglist(data)
Boris Feld
template: add minimal obsfate template function...
r33913
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'p1', requires={b'ctx'})
Yuya Nishihara
templatekw: add p1/p2 keywords which switches the current 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."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
return templateutil.mappingdict({b'ctx': ctx.p1()}, tmpl=_changeidtmpl)
Yuya Nishihara
templatekw: add p1/p2 keywords which switches the current ctx...
r40510
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'p2', requires={b'ctx'})
Yuya Nishihara
templatekw: add p1/p2 keywords which switches the current 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."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
return templateutil.mappingdict({b'ctx': ctx.p2()}, tmpl=_changeidtmpl)
Yuya Nishihara
templatekw: add p1/p2 keywords which switches the current ctx...
r40510
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'p1rev', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showp1rev(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Integer. The repository-local revision number of the changeset's
Yuya Nishihara
templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
r40511 first parent, or -1 if the changeset has no parents. (DEPRECATED)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
epriestley
templatekw: add p1rev, p1node, p2rev, p2node keywords...
r17357 return ctx.p1().rev()
epriestley
templatekw: add parent1, parent1node, parent2, parent2node keywords...
r17355
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'p2rev', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showp2rev(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Integer. The repository-local revision number of the changeset's
Yuya Nishihara
templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
r40511 second parent, or -1 if the changeset has no second parent. (DEPRECATED)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
epriestley
templatekw: add p1rev, p1node, p2rev, p2node keywords...
r17357 return ctx.p2().rev()
epriestley
templatekw: add parent1, parent1node, parent2, parent2node keywords...
r17355
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'p1node', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showp1node(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The identification hash of the changeset's first parent,
epriestley
templatekw: add p1rev, p1node, p2rev, p2node keywords...
r17357 as a 40 digit hexadecimal string. If the changeset has no parents, all
Yuya Nishihara
templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
r40511 digits are 0. (DEPRECATED)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
epriestley
templatekw: add p1rev, p1node, p2rev, p2node keywords...
r17357 return ctx.p1().hex()
epriestley
templatekw: add parent1, parent1node, parent2, parent2node keywords...
r17355
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'p2node', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showp2node(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The identification hash of the changeset's second
epriestley
templatekw: add p1rev, p1node, p2rev, p2node keywords...
r17357 parent, as a 40 digit hexadecimal string. If the changeset has no second
Yuya Nishihara
templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
r40511 parent, all digits are 0. (DEPRECATED)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
epriestley
templatekw: add p1rev, p1node, p2rev, p2node keywords...
r17357 return ctx.p2().hex()
epriestley
templatekw: add parent1, parent1node, parent2, parent2node keywords...
r17355
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'parents', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch remainder of _showlist template keywords to new API
r36616 def showparents(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. The parents of the changeset in "rev:node"
Yuya Nishihara
templatekw: reorder stub of showparents() function...
r26434 format. If the changeset has only one "natural" parent (the predecessor
revision) nothing is shown."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: switch ctx of list expression to rev of {parents} (BC)...
r28270 pctxs = scmutil.meaningfulparents(repo, ctx)
Yuya Nishihara
templater: store revisions as ints so min/max won't compare them as strings...
r34582 prevs = [p.rev() for p in pctxs]
Augie Fackler
formatting: blacken the codebase...
r43346 parents = [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 [(b'rev', p.rev()), (b'node', p.hex()), (b'phase', p.phasestr())]
Augie Fackler
formatting: blacken the codebase...
r43346 for p in pctxs
]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = _showcompatlist(context, mapping, b'parent', parents)
Augie Fackler
formatting: blacken the codebase...
r43346 return _hybrid(
f,
prevs,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lambda x: {b'ctx': repo[x]},
Augie Fackler
formatting: blacken the codebase...
r43346 lambda x: scmutil.formatchangeid(repo[x]),
keytype=int,
)
Yuya Nishihara
templatekw: reorder stub of showparents() function...
r26434
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'phase', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showphase(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """String. The changeset phase name."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Pierre-Yves David
phases: ``{phase}`` template keyword display the phase name...
r15823 return ctx.phasestr()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'phaseidx', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showphaseidx(context, mapping):
Yuya Nishihara
help: hide phaseidx template keyword...
r34992 """Integer. The changeset phase index. (ADVANCED)"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Pierre-Yves David
phases: add a phase template keyword
r15422 return ctx.phase()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'rev', requires={b'ctx'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showrev(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """Integer. The repository-local changeset revision number."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
scmutil: pass ctx object to intrev()...
r32654 return scmutil.intrev(ctx)
Patrick Mezard
cmdutil: extract ctx dependent closures into templatekw
r10054
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'subrepos', requires={b'ctx'})
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 def showsubrepos(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Updated subrepositories in the changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
FUJIWARA Katsunori
templatekw: add 'subrepos' keyword to show updated subrepositories...
r21897 substate = ctx.substate
if not substate:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return compatlist(context, mapping, b'subrepo', [])
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 psubstate = ctx.p1().substate or {}
FUJIWARA Katsunori
templatekw: add 'subrepos' keyword to show updated subrepositories...
r21897 subrepos = []
for sub in substate:
if sub not in psubstate or substate[sub] != psubstate[sub]:
Augie Fackler
formatting: blacken the codebase...
r43346 subrepos.append(sub) # modified or newly added in ctx
FUJIWARA Katsunori
templatekw: add 'subrepos' keyword to show updated subrepositories...
r21897 for sub in psubstate:
if sub not in substate:
Augie Fackler
formatting: blacken the codebase...
r43346 subrepos.append(sub) # removed in ctx
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return compatlist(context, mapping, b'subrepo', sorted(subrepos))
FUJIWARA Katsunori
templatekw: add 'subrepos' keyword to show updated subrepositories...
r21897
Augie Fackler
formatting: blacken the codebase...
r43346
FUJIWARA Katsunori
templatekw: re-add showtags() to list tags keyword up in online help...
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
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'tags', requires={b'repo', b'ctx'})
Yuya Nishihara
templatekw: switch namespace template keywords to new API
r36611 def showtags(context, mapping):
FUJIWARA Katsunori
templatekw: use templatekeyword to mark a function as template keyword...
r28539 """List of strings. Any tags associated with the changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return shownames(context, mapping, b'tags')
FUJIWARA Katsunori
templatekw: re-add showtags() to list tags keyword up in online help...
r23977
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'termwidth', requires={b'ui'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showtermwidth(context, mapping):
Simon Farnsworth
template: provide a termwidth keyword (issue5395)...
r30088 """Integer. The width of the current terminal."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui = context.resource(mapping, b'ui')
Yuya Nishihara
templatekw: minimize resource dependency of {envvars} and {termwidth}...
r36460 return ui.termwidth()
Simon Farnsworth
template: provide a termwidth keyword (issue5395)...
r30088
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'user', requires={b'ctx'})
Yuya Nishihara
templatekw: copy {author} to {user} and document {author} as an alias...
r38983 def showuser(context, mapping):
"""String. The unmodified author of the changeset."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Yuya Nishihara
templatekw: copy {author} to {user} and document {author} as an alias...
r38983 return ctx.user()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'instabilities', requires={b'ctx'})
Yuya Nishihara
templatekw: switch most of showlist template keywords to new API (issue5779)...
r36609 def showinstabilities(context, mapping):
Boris Feld
template: rename troubles templatekw into instabilities...
r33675 """List of strings. Evolution instabilities affecting the changeset.
Denis Laxalde
templatekw: add a "troubles" template keyword...
r30712 (EXPERIMENTAL)
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = context.resource(mapping, b'ctx')
Augie Fackler
formatting: blacken the codebase...
r43346 return compatlist(
context,
mapping,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'instability',
Augie Fackler
formatting: blacken the codebase...
r43346 ctx.instabilities(),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 plural=b'instabilities',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Denis Laxalde
templatekw: add a "troubles" template keyword...
r30712
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'verbosity', requires={b'ui'})
Yuya Nishihara
templatekw: switch non-showlist template keywords to new API
r36531 def showverbosity(context, mapping):
Yuya Nishihara
templatekw: add verbosity keyword to select template by -q/-v/--debug flag...
r34994 """String. The current output verbosity in 'debug', 'quiet', 'verbose',
or ''."""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui = context.resource(mapping, b'ui')
Yuya Nishihara
cmdutil: drop aliases for logcmdutil functions (API)...
r35906 # see logcmdutil.changesettemplater for priority of these flags
Yuya Nishihara
templatekw: add verbosity keyword to select template by -q/-v/--debug flag...
r34994 if ui.debugflag:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'debug'
Yuya Nishihara
templatekw: add verbosity keyword to select template by -q/-v/--debug flag...
r34994 elif ui.quiet:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'quiet'
Yuya Nishihara
templatekw: add verbosity keyword to select template by -q/-v/--debug flag...
r34994 elif ui.verbose:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'verbose'
return b''
Yuya Nishihara
templatekw: add verbosity keyword to select template by -q/-v/--debug flag...
r34994
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @templatekeyword(b'whyunstable', requires={b'repo', b'ctx'})
av6
templates: add whyunstable template keyword
r37703 def showwhyunstable(context, mapping):
"""List of dicts explaining all instabilities of a changeset.
(EXPERIMENTAL)
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo = context.resource(mapping, b'repo')
ctx = context.resource(mapping, b'ctx')
av6
templates: add whyunstable template keyword
r37703
def formatnode(ctx):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'%s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr())
av6
templates: add whyunstable template keyword
r37703
entries = obsutil.whyunstable(repo, ctx)
for entry in entries:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if entry.get(b'divergentnodes'):
dnodes = entry[b'divergentnodes']
Augie Fackler
formatting: blacken the codebase...
r43346 dnhybrid = _hybrid(
None,
[dnode.hex() for dnode in dnodes],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lambda x: {b'ctx': repo[x]},
Augie Fackler
formatting: blacken the codebase...
r43346 lambda x: formatnode(repo[x]),
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 entry[b'divergentnodes'] = dnhybrid
av6
templates: add whyunstable template keyword
r37703
Augie Fackler
formatting: blacken the codebase...
r43346 tmpl = (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'{instability}:{if(divergentnodes, " ")}{divergentnodes} '
b'{reason} {node|short}'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return templateutil.mappinglist(entries, tmpl=tmpl, sep=b'\n')
av6
templates: add whyunstable template keyword
r37703
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
templatekw: move loadkeyword() to bottom...
r34993 def loadkeyword(ui, extname, registrarobj):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """Load template keyword from specified registrarobj"""
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for name, func in pycompat.iteritems(registrarobj._table):
Yuya Nishihara
templatekw: move loadkeyword() to bottom...
r34993 keywords[name] = func
Augie Fackler
formatting: blacken the codebase...
r43346
Patrick Mezard
templates: generate keyword help dynamically
r13585 # tell hggettext to extract docstrings from these functions:
Yuya Nishihara
templatekw: remove dockeywords hack...
r26436 i18nfunctions = keywords.values()