Mercurial > hg
comparison mercurial/cmdutil.py @ 35469:f1c54d003327
templater: move repo, ui and cache to per-engine resources
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 21 Dec 2017 22:05:30 +0900 |
parents | 32c278eb876f |
children | 817a3d20dd01 |
comparison
equal
deleted
inserted
replaced
35468:32c278eb876f | 35469:f1c54d003327 |
---|---|
1841 def __init__(self, ui, repo, tmplspec, matchfn=None, diffopts=None, | 1841 def __init__(self, ui, repo, tmplspec, matchfn=None, diffopts=None, |
1842 buffered=False): | 1842 buffered=False): |
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 self.t = formatter.loadtemplater(ui, tmplspec, | 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': '', |
1853 tmplspec.ref: tmplspec.ref, | 1854 tmplspec.ref: tmplspec.ref, |
1854 'docheader': '', 'docfooter': '', | 1855 'docheader': '', 'docfooter': '', |
1885 def _show(self, ctx, copies, matchfn, hunksfilterfn, props): | 1886 def _show(self, ctx, copies, matchfn, hunksfilterfn, props): |
1886 '''show a single changeset or file revision''' | 1887 '''show a single changeset or file revision''' |
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 |
1898 # since there's inherently a conflict between header (across items) and | 1896 # since there's inherently a conflict between header (across items) and |
1899 # separator (per item) | 1897 # separator (per item) |
2655 spec = ui.config('ui', 'graphnodetemplate') | 2653 spec = ui.config('ui', 'graphnodetemplate') |
2656 if not spec: | 2654 if not spec: |
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 templ = formatter.maketemplater(ui, spec) | 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 |
2673 | 2669 |
2674 def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, | 2670 def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None, |