comparison mercurial/templatekw.py @ 44589:fc1fa3a07af6

templater: introduce wrapper for smartset (API) I want to add a template function which takes a revset as an argument: {somefunc(..., revset(...))} ^^^^^^^^^^^ evaluates to a revslist This wrapper will provide a method to get an underlying smartset. It should also be good for performance since count(revset(...)) will no longer have to fully consume the smartset for example, but that isn't the point of this change.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 15 Mar 2020 15:12:44 +0900
parents 14d0e89520a2
children a825bfbf6642
comparison
equal deleted inserted replaced
44588:2a98b0cd4995 44589:fc1fa3a07af6
871 """Integer. The repository-local changeset revision number.""" 871 """Integer. The repository-local changeset revision number."""
872 ctx = context.resource(mapping, b'ctx') 872 ctx = context.resource(mapping, b'ctx')
873 return scmutil.intrev(ctx) 873 return scmutil.intrev(ctx)
874 874
875 875
876 def showrevslist(context, mapping, name, revs):
877 """helper to generate a list of revisions in which a mapped template will
878 be evaluated"""
879 repo = context.resource(mapping, b'repo')
880 # revs may be a smartset; don't compute it until f() has to be evaluated
881 def f():
882 srevs = [b'%d' % r for r in revs]
883 return _showcompatlist(context, mapping, name, srevs)
884
885 return _hybrid(
886 f,
887 revs,
888 lambda x: {name: x, b'ctx': repo[x]},
889 pycompat.identity,
890 keytype=int,
891 )
892
893
894 @templatekeyword(b'subrepos', requires={b'ctx'}) 876 @templatekeyword(b'subrepos', requires={b'ctx'})
895 def showsubrepos(context, mapping): 877 def showsubrepos(context, mapping):
896 """List of strings. Updated subrepositories in the changeset.""" 878 """List of strings. Updated subrepositories in the changeset."""
897 ctx = context.resource(mapping, b'ctx') 879 ctx = context.resource(mapping, b'ctx')
898 substate = ctx.substate 880 substate = ctx.substate