Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 30012: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 | b1f69dbdd76b |
children | f18cc848b48e |
line wrap: on
line diff
--- a/mercurial/templater.py Sat Sep 17 17:02:56 2016 +1000 +++ b/mercurial/templater.py Fri Sep 23 08:15:05 2016 +0000 @@ -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