Patchwork [3,of,9] templatekw: factor out function to build a list of files per status

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 27, 2018, 2:57 p.m.
Message ID <e0a72c36b24883cf6dd6.1519743476@mimosa>
Download mbox | patch
Permalink /patch/28471/
State New
Headers show

Comments

Yuya Nishihara - Feb. 27, 2018, 2:57 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519544134 -32400
#      Sun Feb 25 16:35:34 2018 +0900
# Node ID e0a72c36b24883cf6dd62144e9b2ca7959fb8b23
# Parent  2f63464d7c83e597c467d930baa9f709186107b7
templatekw: factor out function to build a list of files per status

Removes copy-paste code before switching to the (context, mapping) API.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -464,13 +464,16 @@  def showextras(**args):
     return _hybrid(f, extras, makemap,
                    lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
 
+def _showfilesbystat(args, name, index):
+    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
+    files = getfiles(repo, ctx, revcache)[index]
+    return showlist(name, files, args, element='file')
+
 @templatekeyword('file_adds')
 def showfileadds(**args):
     """List of strings. Files added by this changeset."""
     args = pycompat.byteskwargs(args)
-    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
-    return showlist('file_add', getfiles(repo, ctx, revcache)[1], args,
-                    element='file')
+    return _showfilesbystat(args, 'file_add', 1)
 
 @templatekeyword('file_copies')
 def showfilecopies(**args):
@@ -512,17 +515,13 @@  def showfilecopiesswitch(**args):
 def showfiledels(**args):
     """List of strings. Files removed by this changeset."""
     args = pycompat.byteskwargs(args)
-    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
-    return showlist('file_del', getfiles(repo, ctx, revcache)[2], args,
-                    element='file')
+    return _showfilesbystat(args, 'file_del', 2)
 
 @templatekeyword('file_mods')
 def showfilemods(**args):
     """List of strings. Files modified by this changeset."""
     args = pycompat.byteskwargs(args)
-    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
-    return showlist('file_mod', getfiles(repo, ctx, revcache)[0], args,
-                    element='file')
+    return _showfilesbystat(args, 'file_mod', 0)
 
 @templatekeyword('files')
 def showfiles(**args):