[PATCH 4 of 6] cmdutil: extract file changes closures into templatekw
Patrick Mezard
pmezard at gmail.com
Mon Nov 30 16:34:44 CST 2009
# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1259616498 -3600
# Node ID 9651033b608af8b664eba0962a0fc943235f373b
# Parent 774df2f4538b4dbf1260a71299b95e5fd8cd38d7
cmdutil: extract file changes closures into templatekw
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -814,19 +814,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]
@@ -834,9 +821,6 @@
return self._latesttaginfo(ctx.rev())[1]
defprops = {
- 'file_adds': showadds,
- 'file_dels': showdels,
- 'file_mods': showmods,
'file_copies': showcopies,
'parents': showparents,
'latesttag': showlatesttag,
@@ -848,6 +832,7 @@
props['templ'] = self.t
props['ctx'] = ctx
props['repo'] = self.repo
+ props['cache'] = {}
# 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 @@
if endname in templ:
yield templ(endname, **args)
+def getfiles(repo, ctx, cache):
+ if 'files' not in cache:
+ cache['files'] = repo.status(ctx.parents()[0].node(),
+ ctx.node())[:3]
+ return cache['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, cache, **args):
+ return showlist(templ, 'file_add', getfiles(repo, ctx, cache)[1], **args)
+
+def showfiledels(repo, ctx, templ, cache, **args):
+ return showlist(templ, 'file_del', getfiles(repo, ctx, cache)[2], **args)
+
+def showfilemods(repo, ctx, templ, cache, **args):
+ return showlist(templ, 'file_mod', getfiles(repo, ctx, cache)[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,
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 @@
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', 'cache'):
continue
if hasattr(v, '__call__'):
v = v(**map)
More information about the Mercurial-devel
mailing list