Mercurial > hg-stable
changeset 37072:724f2e21d870
templatekw: stop using _showlist() which is about to be deprecated
Use the new context-based API instead.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 16 Mar 2018 23:01:51 +0900 |
parents | aa97e06a1912 |
children | 1101d6747d2d |
files | mercurial/hgweb/webutil.py mercurial/templatekw.py |
diffstat | 2 files changed, 17 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py Fri Mar 16 22:47:15 2018 +0900 +++ b/mercurial/hgweb/webutil.py Fri Mar 16 23:01:51 2018 +0900 @@ -367,7 +367,7 @@ yield item # teach templater succsandmarkers is switched to (context, mapping) API -succsandmarkers._requires = {'repo', 'ctx', 'templ'} +succsandmarkers._requires = {'repo', 'ctx'} def whyunstable(context, mapping): repo = context.resource(mapping, 'repo') @@ -379,7 +379,7 @@ entry['divergentnodes'] = _siblings(entry['divergentnodes']) yield entry -whyunstable._requires = {'repo', 'ctx', 'templ'} +whyunstable._requires = {'repo', 'ctx'} def commonentry(repo, ctx): node = ctx.node()
--- a/mercurial/templatekw.py Fri Mar 16 22:47:15 2018 +0900 +++ b/mercurial/templatekw.py Fri Mar 16 23:01:51 2018 +0900 @@ -231,18 +231,17 @@ plural='branches') return compatlist(context, mapping, 'branch', [], plural='branches') -@templatekeyword('bookmarks', requires={'repo', 'ctx', 'templ'}) +@templatekeyword('bookmarks', requires={'repo', 'ctx'}) def showbookmarks(context, mapping): """List of strings. Any bookmarks associated with the changeset. Also sets 'active', the name of the active bookmark. """ 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, templ, mapping) + f = _showcompatlist(context, mapping, 'bookmark', bookmarks) return _hybrid(f, bookmarks, makemap, pycompat.identity) @templatekeyword('children', requires={'ctx'}) @@ -304,17 +303,16 @@ env = util.sortdict((k, env[k]) for k in sorted(env)) return compatdict(context, mapping, 'envvar', env, plural='envvars') -@templatekeyword('extras', requires={'ctx', 'templ'}) +@templatekeyword('extras', requires={'ctx'}) def showextras(context, mapping): """List of dicts with key, value entries of the 'extras' field of this changeset.""" 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, templ, mapping, plural='extras') + f = _showcompatlist(context, mapping, 'extra', c, plural='extras') return _hybrid(f, extras, makemap, lambda k: '%s=%s' % (k, util.escapestr(extras[k]))) @@ -424,7 +422,7 @@ # just hosts documentation; should be overridden by template mapping raise error.Abort(_("can't use index in this context")) -@templatekeyword('latesttag', requires={'repo', 'ctx', 'cache', 'templ'}) +@templatekeyword('latesttag', requires={'repo', 'ctx', 'cache'}) def showlatesttag(context, mapping): """List of strings. The global tags on the most recent globally tagged ancestor of this changeset. If no such tags exist, the list @@ -447,8 +445,7 @@ } tags = latesttags[2] - templ = context.resource(mapping, 'templ') - f = _showlist('latesttag', tags, templ, mapping, separator=':') + f = _showcompatlist(context, mapping, 'latesttag', tags, separator=':') return _hybrid(f, tags, makemap, pycompat.identity) @templatekeyword('latesttagdistance', requires={'repo', 'ctx', 'cache'}) @@ -497,7 +494,7 @@ # rev and node are completely different from changeset's. return _mappable(f, None, f, lambda x: {'rev': mrev, 'node': mhex}) -@templatekeyword('obsfate', requires={'ui', 'repo', 'ctx', 'templ'}) +@templatekeyword('obsfate', requires={'ui', 'repo', 'ctx'}) def showobsfate(context, mapping): # this function returns a list containing pre-formatted obsfate strings. # @@ -522,13 +519,12 @@ return compatlist(context, mapping, ns.templatename, names, plural=namespace) -@templatekeyword('namespaces', requires={'repo', 'ctx', 'templ'}) +@templatekeyword('namespaces', requires={'repo', 'ctx'}) def shownamespaces(context, mapping): """Dict of lists. Names attached to this changeset per namespace.""" repo = context.resource(mapping, 'repo') ctx = context.resource(mapping, 'ctx') - templ = context.resource(mapping, 'templ') namespaces = util.sortdict() def makensmapfn(ns): @@ -537,10 +533,10 @@ for k, ns in repo.names.iteritems(): names = ns.names(repo, ctx.node()) - f = _showlist('name', names, templ, mapping) + f = _showcompatlist(context, mapping, 'name', names) namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity) - f = _showlist('namespace', list(namespaces), templ, mapping) + f = _showcompatlist(context, mapping, 'namespace', list(namespaces)) def makemap(ns): return { @@ -633,7 +629,7 @@ return _hybrid(gen(data), data, lambda x: {'successorset': x}, pycompat.identity) -@templatekeyword("succsandmarkers", requires={'repo', 'ctx', 'templ'}) +@templatekeyword("succsandmarkers", requires={'repo', 'ctx'}) def showsuccsandmarkers(context, mapping): """Returns a list of dict for each final successor of ctx. The dict contains successors node id in "successors" keys and the list of @@ -642,7 +638,6 @@ """ repo = context.resource(mapping, 'repo') ctx = context.resource(mapping, 'ctx') - templ = context.resource(mapping, 'templ') values = obsutil.successorsandmarkers(repo, ctx) @@ -673,7 +668,7 @@ data.append({'successors': successors, 'markers': finalmarkers}) - f = _showlist('succsandmarkers', data, templ, mapping) + f = _showcompatlist(context, mapping, 'succsandmarkers', data) return _hybrid(f, data, lambda x: x, pycompat.identity) @templatekeyword('p1rev', requires={'ctx'}) @@ -706,21 +701,20 @@ ctx = context.resource(mapping, 'ctx') return ctx.p2().hex() -@templatekeyword('parents', requires={'repo', 'ctx', 'templ'}) +@templatekeyword('parents', requires={'repo', 'ctx'}) 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.""" 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, templ, mapping) + f = _showcompatlist(context, mapping, 'parent', parents) return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}}, lambda x: scmutil.formatchangeid(repo[x]), keytype=int) @@ -746,8 +740,7 @@ """helper to generate a list of revisions in which a mapped template will be evaluated""" repo = context.resource(mapping, 'repo') - templ = context.resource(mapping, 'templ') - f = _showlist(name, ['%d' % r for r in revs], templ, mapping) + f = _showcompatlist(context, mapping, name, ['%d' % r for r in revs]) return _hybrid(f, revs, lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, pycompat.identity, keytype=int)