Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 34459:a1b89c8ad32d
templater: add experimental support for extdata
This is minimal and non-controversial implementation of extdata() template
function. Originally extdata sources were exposed to the keyword namespace,
but I've changed it to a plain function for simplicity.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 01 Oct 2017 11:13:09 +0100 |
parents | 46f45b7efa30 |
children | b3073e175c17 |
line wrap: on
line diff
--- a/mercurial/templater.py Sun Oct 01 10:50:00 2017 +0100 +++ b/mercurial/templater.py Sun Oct 01 11:13:09 2017 +0100 @@ -24,6 +24,7 @@ registrar, revset as revsetmod, revsetlang, + scmutil, templatefilters, templatekw, util, @@ -593,6 +594,22 @@ return ''.join(chunks) +@templatefunc('extdata(source)', argspec='source') +def extdata(context, mapping, args): + """Show a text read from the specified extdata source. (EXPERIMENTAL)""" + if 'source' not in args: + # i18n: "extdata" is a keyword + raise error.ParseError(_('extdata expects one argument')) + + source = evalstring(context, mapping, args['source']) + cache = mapping['cache'].setdefault('extdata', {}) + ctx = mapping['ctx'] + if source in cache: + data = cache[source] + else: + data = cache[source] = scmutil.extdatasource(ctx.repo(), source) + return data.get(ctx.rev(), '') + @templatefunc('files(pattern)') def files(context, mapping, args): """All files of the current changeset matching the pattern. See