# HG changeset patch # User Yuya Nishihara # Date 2018-08-05 07:14:18 # Node ID 83f8f7b9fa60064a83fcbecff80da5c8393a6639 # Parent a41497b5117cf32865cdf7d24c21af15518cd798 templatekw: alias {file} of files list to {path} This is a part of the name unification. All {path}s will be changed to repository-absolute (i.e. canonical) paths. https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -140,7 +140,7 @@ def files(context, mapping, args): ctx = context.resource(mapping, 'ctx') m = ctx.match([raw]) files = list(ctx.matches(m)) - return templateutil.compatlist(context, mapping, "file", files) + return templateutil.compatfileslist(context, mapping, "file", files) @templatefunc('fill(text[, width[, initialident[, hangindent]]])') def fill(context, mapping, args): diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -297,7 +297,7 @@ def _showfilesbystat(context, mapping, n if 'files' not in revcache: revcache['files'] = ctx.p1().status(ctx)[:3] files = revcache['files'][index] - return compatlist(context, mapping, name, files, element='file') + return templateutil.compatfileslist(context, mapping, name, files) @templatekeyword('file_adds', requires={'ctx', 'revcache'}) def showfileadds(context, mapping): @@ -359,7 +359,7 @@ def showfiles(context, mapping): changeset. """ ctx = context.resource(mapping, 'ctx') - return compatlist(context, mapping, 'file', ctx.files()) + return templateutil.compatfileslist(context, mapping, 'file', ctx.files()) @templatekeyword('graphnode', requires={'repo', 'ctx'}) def showgraphnode(context, mapping): diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py --- a/mercurial/templateutil.py +++ b/mercurial/templateutil.py @@ -570,6 +570,17 @@ def compatlist(context, mapping, name, d f = _showcompatlist(context, mapping, name, data, plural, separator) return hybridlist(data, name=element or name, fmt=fmt, gen=f) +def compatfileslist(context, mapping, name, files): + """Wrap list of file names to support old-style list template and field + names + + This exists for backward compatibility. Use hybridlist for new template + keywords. + """ + f = _showcompatlist(context, mapping, name, files) + return hybrid(f, files, lambda x: {'file': x, 'path': x}, + pycompat.identity) + def _showcompatlist(context, mapping, name, values, plural=None, separator=' '): """Return a generator that renders old-style list template diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t --- a/tests/test-template-functions.t +++ b/tests/test-template-functions.t @@ -1198,6 +1198,12 @@ Test files function 0 + + $ hg log -l1 -T "{files('aa') % '{file}\n'}" + aa + $ hg log -l1 -T "{files('aa') % '{path}\n'}" + aa + $ hg rm a $ hg log -r "wdir()" -T "{rev}\n{join(files('*'), '\n')}\n" 2147483647 diff --git a/tests/test-template-keywords.t b/tests/test-template-keywords.t --- a/tests/test-template-keywords.t +++ b/tests/test-template-keywords.t @@ -745,6 +745,30 @@ Add a commit that does all possible modi $ hg rm a $ hg ci -m "Modify, add, remove, rename" +Test files list: + + $ hg log -l1 -T '{join(file_mods, " ")}\n' + third + $ hg log -l1 -T '{file_mods % "{file}\n"}' + third + $ hg log -l1 -T '{file_mods % "{path}\n"}' + third + + $ hg log -l1 -T '{join(files, " ")}\n' + a b fifth fourth third + $ hg log -l1 -T '{files % "{file}\n"}' + a + b + fifth + fourth + third + $ hg log -l1 -T '{files % "{path}\n"}' + a + b + fifth + fourth + third + Test index keyword: $ hg log -l 2 -T '{index + 10}{files % " {index}:{file}"}\n'