diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -820,19 +820,6 @@ class changeset_templater(changeset_prin def showcopies(repo, ctx, templ, **args): c = [{'name': x[0], 'source': x[1]} for x in copies] return showlist(templ, 'file_copy', c, plural='file_copies', **args) - - files = [] - def getfiles(): - if not files: - files[:] = self.repo.status(ctx.parents()[0].node(), - ctx.node())[:3] - return files - def showmods(repo, ctx, templ, **args): - return showlist(templ, 'file_mod', getfiles()[0], **args) - def showadds(repo, ctx, templ, **args): - return showlist(templ, 'file_add', getfiles()[1], **args) - def showdels(repo, ctx, templ, **args): - return showlist(templ, 'file_del', getfiles()[2], **args) def showlatesttag(repo, ctx, templ, **args): return self._latesttaginfo(ctx.rev())[2] @@ -840,9 +827,6 @@ class changeset_templater(changeset_prin return self._latesttaginfo(ctx.rev())[1] defprops = { - 'file_adds': showadds, - 'file_dels': showdels, - 'file_mods': showmods, 'file_copies': showcopies, 'parents': showparents, 'latesttag': showlatesttag, @@ -854,6 +838,7 @@ class changeset_templater(changeset_prin props['templ'] = self.t props['ctx'] = ctx props['repo'] = self.repo + props['revcache'] = {} # find correct templates for current mode diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -69,6 +69,12 @@ def showlist(templ, name, values, plural if endname in templ: yield templ(endname, **args) +def getfiles(repo, ctx, revcache): + if 'files' not in revcache: + revcache['files'] = repo.status(ctx.parents()[0].node(), + ctx.node())[:3] + return revcache['files'] + def showauthor(repo, ctx, templ, **args): return ctx.user() @@ -99,6 +105,15 @@ def showextras(repo, ctx, templ, **args) args.update(dict(key=key, value=value)) yield templ('extra', **args) +def showfileadds(repo, ctx, templ, revcache, **args): + return showlist(templ, 'file_add', getfiles(repo, ctx, revcache)[1], **args) + +def showfiledels(repo, ctx, templ, revcache, **args): + return showlist(templ, 'file_del', getfiles(repo, ctx, revcache)[2], **args) + +def showfilemods(repo, ctx, templ, revcache, **args): + return showlist(templ, 'file_mod', getfiles(repo, ctx, revcache)[0], **args) + def showfiles(repo, ctx, templ, **args): return showlist(templ, 'file', ctx.files(), **args) @@ -124,6 +139,9 @@ keywords = { 'desc': showdescription, 'diffstat': showdiffstat, 'extras': showextras, + 'file_adds': showfileadds, + 'file_dels': showfiledels, + 'file_mods': showfilemods, 'files': showfiles, 'manifest': showmanifest, 'node': shownode, diff --git a/tests/test-template-engine b/tests/test-template-engine --- a/tests/test-template-engine +++ b/tests/test-template-engine @@ -11,7 +11,7 @@ class mytemplater(object): def process(self, t, map): tmpl = self.loader(t) for k, v in map.iteritems(): - if k in ('templ', 'ctx', 'repo'): + if k in ('templ', 'ctx', 'repo', 'revcache'): continue if hasattr(v, '__call__'): v = v(**map)