# HG changeset patch # User Yuya Nishihara # Date 2018-02-25 10:25:14 # Node ID c3f9d0c303e87dd843ac40a8b85924fa0bcf7f0f # Parent d57f383516f6f4b37706f569cc1a96322b59708a 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] -@templatekeyword('lfs_files') -def lfsfiles(repo, ctx, **args): +@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 @@ -401,17 +401,18 @@ def showbranches(context, mapping): plural='branches') return compatlist(context, mapping, 'branch', [], plural='branches') -@templatekeyword('bookmarks') -def showbookmarks(**args): +@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'}) @@ -473,16 +474,17 @@ def showenvvars(context, mapping): env = util.sortdict((k, env[k]) for k in sorted(env)) return compatdict(context, mapping, 'envvar', env, plural='envvars') -@templatekeyword('extras') -def showextras(**args): +@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]))) @@ -875,21 +877,21 @@ def showp2node(context, mapping): ctx = context.resource(mapping, 'ctx') return ctx.p2().hex() -@templatekeyword('parents') -def showparents(**args): +@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)