Show More
@@ -382,9 +382,7 b' def _runrecursivesymbol(context, mapping' | |||
|
382 | 382 | raise error.Abort(_("recursive reference '%s' in template") % key) |
|
383 | 383 | |
|
384 | 384 | def runsymbol(context, mapping, key, default=''): |
|
385 |
v = mapping |
|
|
386 | if v is None: | |
|
387 | v = context._defaults.get(key) | |
|
385 | v = context.symbol(mapping, key) | |
|
388 | 386 | if v is None: |
|
389 | 387 | # put poison to cut recursion. we can't move this to parsing phase |
|
390 | 388 | # because "x = {x}" is allowed if "x" is a keyword. (issue4758) |
@@ -626,7 +624,7 b' def diff(context, mapping, args):' | |||
|
626 | 624 | return [s] |
|
627 | 625 | return [] |
|
628 | 626 | |
|
629 |
ctx = mapping |
|
|
627 | ctx = context.resource(mapping, 'ctx') | |
|
630 | 628 | chunks = ctx.diff(match=ctx.match([], getpatterns(0), getpatterns(1))) |
|
631 | 629 | |
|
632 | 630 | return ''.join(chunks) |
@@ -639,8 +637,8 b' def extdata(context, mapping, args):' | |||
|
639 | 637 | raise error.ParseError(_('extdata expects one argument')) |
|
640 | 638 | |
|
641 | 639 | source = evalstring(context, mapping, args['source']) |
|
642 |
cache = mapping |
|
|
643 |
ctx = mapping |
|
|
640 | cache = context.resource(mapping, 'cache').setdefault('extdata', {}) | |
|
641 | ctx = context.resource(mapping, 'ctx') | |
|
644 | 642 | if source in cache: |
|
645 | 643 | data = cache[source] |
|
646 | 644 | else: |
@@ -656,7 +654,7 b' def files(context, mapping, args):' | |||
|
656 | 654 | raise error.ParseError(_("files expects one argument")) |
|
657 | 655 | |
|
658 | 656 | raw = evalstring(context, mapping, args[0]) |
|
659 |
ctx = mapping |
|
|
657 | ctx = context.resource(mapping, 'ctx') | |
|
660 | 658 | m = ctx.match([raw]) |
|
661 | 659 | files = list(ctx.matches(m)) |
|
662 | 660 | return templatekw.showlist("file", files, mapping) |
@@ -692,7 +690,7 b' def formatnode(context, mapping, args):' | |||
|
692 | 690 | # i18n: "formatnode" is a keyword |
|
693 | 691 | raise error.ParseError(_("formatnode expects one argument")) |
|
694 | 692 | |
|
695 |
ui = mapping |
|
|
693 | ui = context.resource(mapping, 'ui') | |
|
696 | 694 | node = evalstring(context, mapping, args[0]) |
|
697 | 695 | if ui.debugflag: |
|
698 | 696 | return node |
@@ -858,7 +856,7 b' def label(context, mapping, args):' | |||
|
858 | 856 | # i18n: "label" is a keyword |
|
859 | 857 | raise error.ParseError(_("label expects two arguments")) |
|
860 | 858 | |
|
861 |
ui = mapping |
|
|
859 | ui = context.resource(mapping, 'ui') | |
|
862 | 860 | thing = evalstring(context, mapping, args[1]) |
|
863 | 861 | # preserve unknown symbol as literal so effects like 'red', 'bold', |
|
864 | 862 | # etc. don't need to be quoted |
@@ -1030,7 +1028,7 b' def relpath(context, mapping, args):' | |||
|
1030 | 1028 | # i18n: "relpath" is a keyword |
|
1031 | 1029 | raise error.ParseError(_("relpath expects one argument")) |
|
1032 | 1030 | |
|
1033 |
repo = mapping |
|
|
1031 | repo = context.resource(mapping, 'ctx').repo() | |
|
1034 | 1032 | path = evalstring(context, mapping, args[0]) |
|
1035 | 1033 | return repo.pathto(path) |
|
1036 | 1034 | |
@@ -1043,7 +1041,7 b' def revset(context, mapping, args):' | |||
|
1043 | 1041 | raise error.ParseError(_("revset expects one or more arguments")) |
|
1044 | 1042 | |
|
1045 | 1043 | raw = evalstring(context, mapping, args[0]) |
|
1046 |
ctx = mapping |
|
|
1044 | ctx = context.resource(mapping, 'ctx') | |
|
1047 | 1045 | repo = ctx.repo() |
|
1048 | 1046 | |
|
1049 | 1047 | def query(expr): |
@@ -1055,7 +1053,8 b' def revset(context, mapping, args):' | |||
|
1055 | 1053 | revs = query(revsetlang.formatspec(raw, *formatargs)) |
|
1056 | 1054 | revs = list(revs) |
|
1057 | 1055 | else: |
|
1058 | revsetcache = mapping['cache'].setdefault("revsetcache", {}) | |
|
1056 | cache = context.resource(mapping, 'cache') | |
|
1057 | revsetcache = cache.setdefault("revsetcache", {}) | |
|
1059 | 1058 | if raw in revsetcache: |
|
1060 | 1059 | revs = revsetcache[raw] |
|
1061 | 1060 | else: |
@@ -1116,7 +1115,7 b' def shortest(context, mapping, args):' | |||
|
1116 | 1115 | # _partialmatch() of filtered changelog could take O(len(repo)) time, |
|
1117 | 1116 | # which would be unacceptably slow. so we look for hash collision in |
|
1118 | 1117 | # unfiltered space, which means some hashes may be slightly longer. |
|
1119 |
cl = mapping |
|
|
1118 | cl = context.resource(mapping, 'ctx')._repo.unfiltered().changelog | |
|
1120 | 1119 | return cl.shortest(node, minlength) |
|
1121 | 1120 | |
|
1122 | 1121 | @templatefunc('strip(text[, chars])') |
@@ -1302,6 +1301,18 b' class engine(object):' | |||
|
1302 | 1301 | self._aliasmap = _aliasrules.buildmap(aliases) |
|
1303 | 1302 | self._cache = {} # key: (func, data) |
|
1304 | 1303 | |
|
1304 | def symbol(self, mapping, key): | |
|
1305 | """Resolve symbol to value or function; None if nothing found""" | |
|
1306 | v = mapping.get(key) | |
|
1307 | if v is None: | |
|
1308 | v = self._defaults.get(key) | |
|
1309 | return v | |
|
1310 | ||
|
1311 | def resource(self, mapping, key): | |
|
1312 | """Return internal data (e.g. cache) used for keyword/function | |
|
1313 | evaluation""" | |
|
1314 | return mapping[key] | |
|
1315 | ||
|
1305 | 1316 | def _load(self, t): |
|
1306 | 1317 | '''load, parse, and cache a template''' |
|
1307 | 1318 | if t not in self._cache: |
General Comments 0
You need to be logged in to leave comments.
Login now