Mercurial > hg
changeset 39367:83f8f7b9fa60
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
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 05 Aug 2018 16:14:18 +0900 |
parents | a41497b5117c |
children | 5b1d406b39f1 |
files | mercurial/templatefuncs.py mercurial/templatekw.py mercurial/templateutil.py tests/test-template-functions.t tests/test-template-keywords.t |
diffstat | 5 files changed, 44 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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):
--- 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
--- 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
--- 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'