Mercurial > hg
comparison mercurial/templater.py @ 34458: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 |
comparison
equal
deleted
inserted
replaced
34457:2c3b8fa3211b | 34458:a1b89c8ad32d |
---|---|
22 parser, | 22 parser, |
23 pycompat, | 23 pycompat, |
24 registrar, | 24 registrar, |
25 revset as revsetmod, | 25 revset as revsetmod, |
26 revsetlang, | 26 revsetlang, |
27 scmutil, | |
27 templatefilters, | 28 templatefilters, |
28 templatekw, | 29 templatekw, |
29 util, | 30 util, |
30 ) | 31 ) |
31 | 32 |
591 ctx = mapping['ctx'] | 592 ctx = mapping['ctx'] |
592 chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1))) | 593 chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1))) |
593 | 594 |
594 return ''.join(chunks) | 595 return ''.join(chunks) |
595 | 596 |
597 @templatefunc('extdata(source)', argspec='source') | |
598 def extdata(context, mapping, args): | |
599 """Show a text read from the specified extdata source. (EXPERIMENTAL)""" | |
600 if 'source' not in args: | |
601 # i18n: "extdata" is a keyword | |
602 raise error.ParseError(_('extdata expects one argument')) | |
603 | |
604 source = evalstring(context, mapping, args['source']) | |
605 cache = mapping['cache'].setdefault('extdata', {}) | |
606 ctx = mapping['ctx'] | |
607 if source in cache: | |
608 data = cache[source] | |
609 else: | |
610 data = cache[source] = scmutil.extdatasource(ctx.repo(), source) | |
611 return data.get(ctx.rev(), '') | |
612 | |
596 @templatefunc('files(pattern)') | 613 @templatefunc('files(pattern)') |
597 def files(context, mapping, args): | 614 def files(context, mapping, args): |
598 """All files of the current changeset matching the pattern. See | 615 """All files of the current changeset matching the pattern. See |
599 :hg:`help patterns`.""" | 616 :hg:`help patterns`.""" |
600 if not len(args) == 1: | 617 if not len(args) == 1: |