mercurial/templatefuncs.py
changeset 38448 dae829b4de78
parent 38428 aa98392eb5b0
child 38449 bc8d925342f0
--- a/mercurial/templatefuncs.py	Sun Jun 17 16:10:38 2018 +0900
+++ b/mercurial/templatefuncs.py	Thu Jun 14 22:33:26 2018 +0900
@@ -166,6 +166,17 @@
 
     return templatefilters.fill(text, width, initindent, hangindent)
 
+@templatefunc('filter(iterable)')
+def filter_(context, mapping, args):
+    """Remove empty elements from a list or a dict."""
+    if len(args) != 1:
+        # i18n: "filter" is a keyword
+        raise error.ParseError(_("filter expects one argument"))
+    iterable = evalwrapped(context, mapping, args[0])
+    def select(w):
+        return w.tobool(context, mapping)
+    return iterable.filter(context, mapping, select)
+
 @templatefunc('formatnode(node)', requires={'ui'})
 def formatnode(context, mapping, args):
     """Obtain the preferred form of a changeset hash. (DEPRECATED)"""