Mercurial > hg
changeset 10056:1a114aca93fa
cmdutil: extract file changes closures into templatekw
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 13 Dec 2009 18:06:24 +0100 |
parents | e400a511e63a |
children | babc00a82c5e |
files | mercurial/cmdutil.py mercurial/templatekw.py tests/test-template-engine |
diffstat | 3 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun Dec 13 18:06:23 2009 +0100 +++ b/mercurial/cmdutil.py Sun Dec 13 18:06:24 2009 +0100 @@ -820,19 +820,6 @@ 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 @@ 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 @@ props['templ'] = self.t props['ctx'] = ctx props['repo'] = self.repo + props['revcache'] = {} # find correct templates for current mode
--- a/mercurial/templatekw.py Sun Dec 13 18:06:23 2009 +0100 +++ b/mercurial/templatekw.py Sun Dec 13 18:06:24 2009 +0100 @@ -69,6 +69,12 @@ 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 @@ 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 @@ 'desc': showdescription, 'diffstat': showdiffstat, 'extras': showextras, + 'file_adds': showfileadds, + 'file_dels': showfiledels, + 'file_mods': showfilemods, 'files': showfiles, 'manifest': showmanifest, 'node': shownode,
--- a/tests/test-template-engine Sun Dec 13 18:06:23 2009 +0100 +++ b/tests/test-template-engine Sun Dec 13 18:06:24 2009 +0100 @@ -11,7 +11,7 @@ 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)