Mercurial > hg > mercurial-source
changeset 30787:e83f89d3b1f7
templates: add built-in files() function
We already support multiple primitive for listing files, which were
affected by the current changeset.
This patch adds files() which returns files of the current changeset
matching a given pattern or fileset query via the "set:" prefix.
author | Hannes Oldenburg <hannes.christian.oldenburg@gmail.com> |
---|---|
date | Fri, 23 Sep 2016 08:15:05 +0000 |
parents | aca0954d3739 |
children | d81fe5af92b8 |
files | mercurial/help/templates.txt mercurial/templater.py tests/test-command-template.t tests/test-help.t |
diffstat | 4 files changed, 41 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/help/templates.txt +++ b/mercurial/help/templates.txt @@ -95,6 +95,10 @@ $ hg log -r 0 --template "files: {join(files, ', ')}\n" +- Join the list of files ending with ".py" with a ", ":: + + $ hg log -r 0 --template "pythonfiles: {join(files('**.py'), ', ')}\n" + - Separate non-empty arguments by a " ":: $ hg log -r 0 --template "{separate(' ', node, bookmarks, tags}\n"
--- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -480,6 +480,20 @@ return ''.join(chunks) +@templatefunc('files(pattern)') +def files(context, mapping, args): + """All files of the current changeset matching the pattern. See + :hg:`help patterns`.""" + if not len(args) == 1: + # i18n: "files" is a keyword + raise error.ParseError(_("files expects one argument")) + + raw = evalstring(context, mapping, args[0]) + ctx = mapping['ctx'] + m = ctx.match([raw]) + files = list(ctx.matches(m)) + return templatekw.showlist("file", files, **mapping) + @templatefunc('fill(text[, width[, initialident[, hangindent]]])') def fill(context, mapping, args): """Fill many
--- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -3501,6 +3501,26 @@ 5:13207e5a10d9fd28ec424934298e176197f2c67f, 4:bbe44766e73d5f11ed2177f1838de10c53ef3e74 +Test files function + + $ hg log -T "{rev}\n{join(files('*'), '\n')}\n" + 2 + a + aa + b + 1 + a + 0 + a + + $ hg log -T "{rev}\n{join(files('aa'), '\n')}\n" + 2 + aa + 1 + + 0 + + Test active bookmark templating $ hg book foo
--- a/tests/test-help.t +++ b/tests/test-help.t @@ -1551,6 +1551,9 @@ $ hg help template.files files List of strings. All files modified, added, or removed by this changeset. + files(pattern) + All files of the current changeset matching the pattern. See + 'hg help patterns'. Test section lookup by translated message