Show More
@@ -252,7 +252,9 b' def showstack(ui, repo, displayer):' | |||||
252 | # our simplicity and the customizations required. |
|
252 | # our simplicity and the customizations required. | |
253 | # TODO use proper graph symbols from graphmod |
|
253 | # TODO use proper graph symbols from graphmod | |
254 |
|
254 | |||
255 | shortesttmpl = formatter.maketemplater(ui, '{shortest(node, %d)}' % nodelen) |
|
255 | tres = formatter.templateresources(ui, repo) | |
|
256 | shortesttmpl = formatter.maketemplater(ui, '{shortest(node, %d)}' % nodelen, | |||
|
257 | resources=tres) | |||
256 | def shortest(ctx): |
|
258 | def shortest(ctx): | |
257 | return shortesttmpl.render({'ctx': ctx, 'node': ctx.hex()}) |
|
259 | return shortesttmpl.render({'ctx': ctx, 'node': ctx.hex()}) | |
258 |
|
260 | |||
@@ -438,7 +440,10 b' def longestshortest(repo, revs, minlen=4' | |||||
438 | If we fail to do this, a value of e.g. ``10023`` could mean either |
|
440 | If we fail to do this, a value of e.g. ``10023`` could mean either | |
439 | revision 10023 or node ``10023abc...``. |
|
441 | revision 10023 or node ``10023abc...``. | |
440 | """ |
|
442 | """ | |
441 |
t |
|
443 | tres = formatter.templateresources(repo.ui, repo) | |
|
444 | tmpl = formatter.maketemplater(repo.ui, '{shortest(node, %d)}' % minlen, | |||
|
445 | resources=tres) | |||
|
446 | ||||
442 | lens = [minlen] |
|
447 | lens = [minlen] | |
443 | for rev in revs: |
|
448 | for rev in revs: | |
444 | ctx = repo[rev] |
|
449 | ctx = repo[rev] |
@@ -1843,10 +1843,11 b' class changeset_templater(changeset_prin' | |||||
1843 | diffopts = diffopts or {} |
|
1843 | diffopts = diffopts or {} | |
1844 |
|
1844 | |||
1845 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1845 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) | |
1846 |
|
|
1846 | tres = formatter.templateresources(ui, repo) | |
|
1847 | self.t = formatter.loadtemplater(ui, tmplspec, resources=tres, | |||
1847 | cache=templatekw.defaulttempl) |
|
1848 | cache=templatekw.defaulttempl) | |
1848 | self._counter = itertools.count() |
|
1849 | self._counter = itertools.count() | |
1849 | self.cache = {} |
|
1850 | self.cache = tres['cache'] # shared with _graphnodeformatter() | |
1850 |
|
1851 | |||
1851 | self._tref = tmplspec.ref |
|
1852 | self._tref = tmplspec.ref | |
1852 | self._parts = {'header': '', 'footer': '', |
|
1853 | self._parts = {'header': '', 'footer': '', | |
@@ -1887,11 +1888,8 b' class changeset_templater(changeset_prin' | |||||
1887 | props = props.copy() |
|
1888 | props = props.copy() | |
1888 | props.update(templatekw.keywords) |
|
1889 | props.update(templatekw.keywords) | |
1889 | props['ctx'] = ctx |
|
1890 | props['ctx'] = ctx | |
1890 | props['repo'] = self.repo |
|
|||
1891 | props['ui'] = self.repo.ui |
|
|||
1892 | props['index'] = index = next(self._counter) |
|
1891 | props['index'] = index = next(self._counter) | |
1893 | props['revcache'] = {'copies': copies} |
|
1892 | props['revcache'] = {'copies': copies} | |
1894 | props['cache'] = self.cache |
|
|||
1895 | props = pycompat.strkwargs(props) |
|
1893 | props = pycompat.strkwargs(props) | |
1896 |
|
1894 | |||
1897 | # write separator, which wouldn't work well with the header part below |
|
1895 | # write separator, which wouldn't work well with the header part below | |
@@ -2657,16 +2655,14 b' def _graphnodeformatter(ui, displayer):' | |||||
2657 | return templatekw.showgraphnode # fast path for "{graphnode}" |
|
2655 | return templatekw.showgraphnode # fast path for "{graphnode}" | |
2658 |
|
2656 | |||
2659 | spec = templater.unquotestring(spec) |
|
2657 | spec = templater.unquotestring(spec) | |
2660 |
t |
|
2658 | tres = formatter.templateresources(ui) | |
2661 | cache = {} |
|
|||
2662 | if isinstance(displayer, changeset_templater): |
|
2659 | if isinstance(displayer, changeset_templater): | |
2663 | cache = displayer.cache # reuse cache of slow templates |
|
2660 | tres['cache'] = displayer.cache # reuse cache of slow templates | |
|
2661 | templ = formatter.maketemplater(ui, spec, resources=tres) | |||
2664 | props = templatekw.keywords.copy() |
|
2662 | props = templatekw.keywords.copy() | |
2665 | props['cache'] = cache |
|
|||
2666 | def formatnode(repo, ctx): |
|
2663 | def formatnode(repo, ctx): | |
2667 | props['ctx'] = ctx |
|
2664 | props['ctx'] = ctx | |
2668 | props['repo'] = repo |
|
2665 | props['repo'] = repo | |
2669 | props['ui'] = repo.ui |
|
|||
2670 | props['revcache'] = {} |
|
2666 | props['revcache'] = {} | |
2671 | return templ.render(props) |
|
2667 | return templ.render(props) | |
2672 | return formatnode |
|
2668 | return formatnode |
@@ -2361,8 +2361,8 b' def debugtemplate(ui, repo, tmpl, **opts' | |||||
2361 | ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n') |
|
2361 | ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n') | |
2362 |
|
2362 | |||
2363 | if revs is None: |
|
2363 | if revs is None: | |
2364 |
t = formatter. |
|
2364 | tres = formatter.templateresources(ui, repo) | |
2365 | props['ui'] = ui |
|
2365 | t = formatter.maketemplater(ui, tmpl, resources=tres) | |
2366 | ui.write(t.render(props)) |
|
2366 | ui.write(t.render(props)) | |
2367 | else: |
|
2367 | else: | |
2368 | displayer = cmdutil.makelogtemplater(ui, repo, tmpl) |
|
2368 | displayer = cmdutil.makelogtemplater(ui, repo, tmpl) |
@@ -581,7 +581,8 b' def _formatlabels(repo, fcd, fco, fca, l' | |||||
581 | ui = repo.ui |
|
581 | ui = repo.ui | |
582 | template = ui.config('ui', 'mergemarkertemplate') |
|
582 | template = ui.config('ui', 'mergemarkertemplate') | |
583 | template = templater.unquotestring(template) |
|
583 | template = templater.unquotestring(template) | |
584 |
t |
|
584 | tres = formatter.templateresources(ui, repo) | |
|
585 | tmpl = formatter.maketemplater(ui, template, resources=tres) | |||
585 |
|
586 | |||
586 | pad = max(len(l) for l in labels) |
|
587 | pad = max(len(l) for l in labels) | |
587 |
|
588 |
@@ -363,11 +363,11 b' class templateformatter(baseformatter):' | |||||
363 | self._out = out |
|
363 | self._out = out | |
364 | spec = lookuptemplate(ui, topic, opts.get('template', '')) |
|
364 | spec = lookuptemplate(ui, topic, opts.get('template', '')) | |
365 | self._tref = spec.ref |
|
365 | self._tref = spec.ref | |
366 |
self._t = loadtemplater(ui, spec, |
|
366 | self._t = loadtemplater(ui, spec, resources=templateresources(ui), | |
|
367 | cache=templatekw.defaulttempl) | |||
367 | self._parts = templatepartsmap(spec, self._t, |
|
368 | self._parts = templatepartsmap(spec, self._t, | |
368 | ['docheader', 'docfooter', 'separator']) |
|
369 | ['docheader', 'docfooter', 'separator']) | |
369 | self._counter = itertools.count() |
|
370 | self._counter = itertools.count() | |
370 | self._cache = {} # for templatekw/funcs to store reusable data |
|
|||
371 | self._renderitem('docheader', {}) |
|
371 | self._renderitem('docheader', {}) | |
372 |
|
372 | |||
373 | def _showitem(self): |
|
373 | def _showitem(self): | |
@@ -395,7 +395,7 b' class templateformatter(baseformatter):' | |||||
395 | props['repo'] = props['ctx'].repo() |
|
395 | props['repo'] = props['ctx'].repo() | |
396 | props['revcache'] = {} |
|
396 | props['revcache'] = {} | |
397 | props = pycompat.strkwargs(props) |
|
397 | props = pycompat.strkwargs(props) | |
398 |
g = self._t(ref, |
|
398 | g = self._t(ref, **props) | |
399 | self._out.write(templater.stringify(g)) |
|
399 | self._out.write(templater.stringify(g)) | |
400 |
|
400 | |||
401 | def end(self): |
|
401 | def end(self): | |
@@ -486,6 +486,15 b' def maketemplater(ui, tmpl, resources=No' | |||||
486 | t.cache[''] = tmpl |
|
486 | t.cache[''] = tmpl | |
487 | return t |
|
487 | return t | |
488 |
|
488 | |||
|
489 | def templateresources(ui, repo=None): | |||
|
490 | """Create a dict of template resources designed for the default templatekw | |||
|
491 | and function""" | |||
|
492 | return { | |||
|
493 | 'cache': {}, # for templatekw/funcs to store reusable data | |||
|
494 | 'repo': repo, | |||
|
495 | 'ui': ui, | |||
|
496 | } | |||
|
497 | ||||
489 | def formatter(ui, out, topic, opts): |
|
498 | def formatter(ui, out, topic, opts): | |
490 | template = opts.get("template", "") |
|
499 | template = opts.get("template", "") | |
491 | if template == "json": |
|
500 | if template == "json": |
@@ -204,6 +204,10 b' never cause crash:' | |||||
204 | $ hg log -r 'wdir()' -T '{manifest}\n' |
|
204 | $ hg log -r 'wdir()' -T '{manifest}\n' | |
205 |
|
205 | |||
206 |
|
206 | |||
|
207 | Internal resources shouldn't be exposed (issue5699): | |||
|
208 | ||||
|
209 | $ hg log -r. -T '{cache}{repo}{templ}{ui}' | |||
|
210 | ||||
207 | Quoting for ui.logtemplate |
|
211 | Quoting for ui.logtemplate | |
208 |
|
212 | |||
209 | $ hg tip --config "ui.logtemplate={rev}\n" |
|
213 | $ hg tip --config "ui.logtemplate={rev}\n" |
General Comments 0
You need to be logged in to leave comments.
Login now