# HG changeset patch # User Yuya Nishihara # Date 1533453258 -32400 # 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 -r a41497b5117c -r 83f8f7b9fa60 mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py Wed Aug 29 18:52:09 2018 +0300 +++ b/mercurial/templatefuncs.py Sun Aug 05 16:14:18 2018 +0900 @@ -140,7 +140,7 @@ 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 -r a41497b5117c -r 83f8f7b9fa60 mercurial/templatekw.py --- a/mercurial/templatekw.py Wed Aug 29 18:52:09 2018 +0300 +++ b/mercurial/templatekw.py Sun Aug 05 16:14:18 2018 +0900 @@ -297,7 +297,7 @@ 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 @@ 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 -r a41497b5117c -r 83f8f7b9fa60 mercurial/templateutil.py --- a/mercurial/templateutil.py Wed Aug 29 18:52:09 2018 +0300 +++ b/mercurial/templateutil.py Sun Aug 05 16:14:18 2018 +0900 @@ -570,6 +570,17 @@ 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 -r a41497b5117c -r 83f8f7b9fa60 tests/test-template-functions.t --- a/tests/test-template-functions.t Wed Aug 29 18:52:09 2018 +0300 +++ b/tests/test-template-functions.t Sun Aug 05 16:14:18 2018 +0900 @@ -1198,6 +1198,12 @@ 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 -r a41497b5117c -r 83f8f7b9fa60 tests/test-template-keywords.t --- a/tests/test-template-keywords.t Wed Aug 29 18:52:09 2018 +0300 +++ b/tests/test-template-keywords.t Sun Aug 05 16:14:18 2018 +0900 @@ -745,6 +745,30 @@ $ 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'