templatekw: extract function that computes and caches file status
authorYuya Nishihara <yuya@tcha.org>
Sun, 29 Jul 2018 21:39:12 +0900
changeset 39597 164827563426
parent 39596 409c42d6a570
child 39598 42209f55c599
templatekw: extract function that computes and caches file status
mercurial/templatekw.py
--- a/mercurial/templatekw.py	Thu Sep 13 22:32:51 2018 +0900
+++ b/mercurial/templatekw.py	Sun Jul 29 21:39:12 2018 +0900
@@ -291,12 +291,16 @@
     return _hybrid(f, extras, makemap,
                    lambda k: '%s=%s' % (k, stringutil.escapestr(extras[k])))
 
-def _showfilesbystat(context, mapping, name, index):
+def _getfilestatus(context, mapping):
     ctx = context.resource(mapping, 'ctx')
     revcache = context.resource(mapping, 'revcache')
     if 'files' not in revcache:
         revcache['files'] = ctx.p1().status(ctx)[:3]
-    files = revcache['files'][index]
+    return revcache['files']
+
+def _showfilesbystat(context, mapping, name, index):
+    stat = _getfilestatus(context, mapping)
+    files = stat[index]
     return templateutil.compatfileslist(context, mapping, name, files)
 
 @templatekeyword('file_adds', requires={'ctx', 'revcache'})