[PATCH] templates: add built-in fileset() function

Hannes Oldenburg hannes.christian.oldenburg at gmail.com
Tue Sep 20 11:57:41 EDT 2016


# HG changeset patch
# User Hannes Oldenburg <hannes.christian.oldenburg at gmail.com>
# Date 1474379333 0
#      Tue Sep 20 13:48:53 2016 +0000
# Node ID cf2156395bff0e3fc4a6604b8aa45b5b7829ba98
# Parent  285a8c3e53f2183438f0cdbc238e4ab851d0d110
templates: add built-in fileset() function

We already support multiple primitive for listing files, which were
affected by the current changeset.
This patch adds fileset() which runs a fileset query with the current
changeset.

diff -r 285a8c3e53f2 -r cf2156395bff mercurial/help/templates.txt
--- a/mercurial/help/templates.txt	Tue May 03 13:36:12 2016 +0900
+++ b/mercurial/help/templates.txt	Tue Sep 20 13:48:53 2016 +0000
@@ -95,6 +95,10 @@
 
    $ hg log -r 0 --template "files: {join(files, ', ')}\n"
 
+- Join the list of files with .py ending Filesets
+
+   $ hg log -r 0 --template "pythonfiles: {join(fileset('**.py'), ', ')}\n"
+
 - Separate non-empty arguments by a " "::
 
    $ hg log -r 0 --template "{separate(' ', node, bookmarks, tags}\n"
diff -r 285a8c3e53f2 -r cf2156395bff mercurial/templater.py
--- a/mercurial/templater.py	Tue May 03 13:36:12 2016 +0900
+++ b/mercurial/templater.py	Tue Sep 20 13:48:53 2016 +0000
@@ -699,6 +699,24 @@
         tzoffset = util.makedate()[1]
     return (date[0], tzoffset)
 
+ at templatefunc('fileset(query)')
+def fileset(context, mapping, args):
+    """Execute a fileset set query with the current changeset. See
+    :hg:`help fileset`."""
+    if not len(args) == 1:
+        # i18n: "revset" is a keyword
+        raise error.ParseError(_("fileset expects no arguments"))
+
+    raw = evalstring(context, mapping, args[0])
+    ctx = mapping['ctx']
+    filesetcache = mapping['cache'].setdefault("filesetcache", {})
+    if raw in filesetcache:
+        files  = filesetcache[raw]
+    else:
+        files = ctx.getfileset(raw)
+        filesetcache[raw] = files
+    return templatekw.showlist("file", files, **mapping)
+
 @templatefunc('revset(query[, formatargs...])')
 def revset(context, mapping, args):
     """Execute a revision set query. See
diff -r 285a8c3e53f2 -r cf2156395bff tests/test-command-template.t
--- a/tests/test-command-template.t	Tue May 03 13:36:12 2016 +0900
+++ b/tests/test-command-template.t	Tue Sep 20 13:48:53 2016 +0000
@@ -3501,6 +3501,12 @@
   5:13207e5a10d9fd28ec424934298e176197f2c67f,
   4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
 
+Test fileset function
+
+  $ hg log -r 0 -T "{rev}\n{join(fileset('*'), '\n')}\n"
+  0
+  a
+
 Test active bookmark templating
 
   $ hg book foo


More information about the Mercurial-devel mailing list