# HG changeset patch # User Yuya Nishihara # Date 2018-02-25 07:35:34 # Node ID e71a3c0a90b0c038544e7d26c759ff357273d022 # Parent 7b74afec67720d4922eea1fe11af639aa8c7fc3e templatekw: factor out function to build a list of files per status Removes copy-paste code before switching to the (context, mapping) API. 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):