Patchwork [1,of,4] templatekw: extract function that computes and caches file status

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 13, 2018, 2:10 p.m.
Message ID <f1e582f01fcc7382196e.1536847828@mimosa>
Download mbox | patch
Permalink /patch/34600/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 13, 2018, 2:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1532867952 -32400
#      Sun Jul 29 21:39:12 2018 +0900
# Node ID f1e582f01fcc7382196eb51e03a7864f66f2b87e
# Parent  69e8ae1380b8b506adc5efb470c555121cb3a964
templatekw: extract function that computes and caches file status

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -291,12 +291,16 @@  def showextras(context, mapping):
     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'})