[PATCH 09 of 10] templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara
yuya at tcha.org
Thu Mar 1 20:51:59 EST 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1519554314 -32400
# Sun Feb 25 19:25:14 2018 +0900
# Node ID 0e49bbe25cdc0eb0898737dd4f584e89f8b8eb6a
# Parent 852829295891f2decb6132113f1f1d437c376f6a
templatekw: switch remainder of _showlist template keywords to new API
diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -356,11 +356,12 @@ def lfsfileset(mctx, x):
return [f for f in mctx.subset
if wrapper.pointerfromctx(mctx.ctx, f, removed=True) is not None]
- at templatekeyword('lfs_files')
-def lfsfiles(repo, ctx, **args):
+ at templatekeyword('lfs_files', requires={'ctx', 'templ'})
+def lfsfiles(context, mapping):
"""List of strings. All files modified, added, or removed by this
changeset."""
- args = pycompat.byteskwargs(args)
+ ctx = context.resource(mapping, 'ctx')
+ templ = context.resource(mapping, 'templ')
pointers = wrapper.pointersfromctx(ctx, removed=True) # {path: pointer}
files = sorted(pointers.keys())
@@ -378,7 +379,7 @@ def lfsfiles(repo, ctx, **args):
}
# TODO: make the separator ', '?
- f = templatekw._showlist('lfs_file', files, args['templ'], args)
+ f = templatekw._showlist('lfs_file', files, templ, mapping)
return templatekw._hybrid(f, files, makemap, pycompat.identity)
@command('debuglfsupload',
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -399,17 +399,18 @@ def showbranches(context, mapping):
plural='branches')
return compatlist(context, mapping, 'branch', [], plural='branches')
- at templatekeyword('bookmarks')
-def showbookmarks(**args):
+ at templatekeyword('bookmarks', requires={'repo', 'ctx', 'templ'})
+def showbookmarks(context, mapping):
"""List of strings. Any bookmarks associated with the
changeset. Also sets 'active', the name of the active bookmark.
"""
- args = pycompat.byteskwargs(args)
- repo = args['ctx']._repo
- bookmarks = args['ctx'].bookmarks()
+ repo = context.resource(mapping, 'repo')
+ ctx = context.resource(mapping, 'ctx')
+ templ = context.resource(mapping, 'templ')
+ bookmarks = ctx.bookmarks()
active = repo._activebookmark
makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
- f = _showlist('bookmark', bookmarks, args['templ'], args)
+ f = _showlist('bookmark', bookmarks, templ, mapping)
return _hybrid(f, bookmarks, makemap, pycompat.identity)
@templatekeyword('children', requires={'ctx', 'templ'})
@@ -471,16 +472,17 @@ def showenvvars(context, mapping):
env = util.sortdict((k, env[k]) for k in sorted(env))
return compatdict(context, mapping, 'envvar', env, plural='envvars')
- at templatekeyword('extras')
-def showextras(**args):
+ at templatekeyword('extras', requires={'ctx', 'templ'})
+def showextras(context, mapping):
"""List of dicts with key, value entries of the 'extras'
field of this changeset."""
- args = pycompat.byteskwargs(args)
- extras = args['ctx'].extra()
+ ctx = context.resource(mapping, 'ctx')
+ templ = context.resource(mapping, 'templ')
+ extras = ctx.extra()
extras = util.sortdict((k, extras[k]) for k in sorted(extras))
makemap = lambda k: {'key': k, 'value': extras[k]}
c = [makemap(k) for k in extras]
- f = _showlist('extra', c, args['templ'], args, plural='extras')
+ f = _showlist('extra', c, templ, mapping, plural='extras')
return _hybrid(f, extras, makemap,
lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
@@ -873,21 +875,21 @@ def showp2node(context, mapping):
ctx = context.resource(mapping, 'ctx')
return ctx.p2().hex()
- at templatekeyword('parents')
-def showparents(**args):
+ at templatekeyword('parents', requires={'repo', 'ctx', 'templ'})
+def showparents(context, mapping):
"""List of strings. The parents of the changeset in "rev:node"
format. If the changeset has only one "natural" parent (the predecessor
revision) nothing is shown."""
- args = pycompat.byteskwargs(args)
- repo = args['repo']
- ctx = args['ctx']
+ repo = context.resource(mapping, 'repo')
+ ctx = context.resource(mapping, 'ctx')
+ templ = context.resource(mapping, 'templ')
pctxs = scmutil.meaningfulparents(repo, ctx)
prevs = [p.rev() for p in pctxs]
parents = [[('rev', p.rev()),
('node', p.hex()),
('phase', p.phasestr())]
for p in pctxs]
- f = _showlist('parent', parents, args['templ'], args)
+ f = _showlist('parent', parents, templ, mapping)
return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}},
lambda x: scmutil.formatchangeid(repo[x]), keytype=int)
More information about the Mercurial-devel
mailing list