changeset 14682:8785fd757077

fileset: add grep predicate
author Matt Mackall <mpm@selenic.com>
date Sat, 18 Jun 2011 16:53:49 -0500
parents 0744db5eb51c
children 281102f37b24
files mercurial/fileset.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/fileset.py	Sat Jun 18 16:53:49 2011 -0500
+++ b/mercurial/fileset.py	Sat Jun 18 16:53:49 2011 -0500
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
-import parser, error, util, merge
+import parser, error, util, merge, re
 from i18n import _
 
 elements = {
@@ -235,12 +235,21 @@
     ignore = mctx.ctx._repo.dirstate._ignore
     return [f for f in mctx.subset if ignore(f)]
 
+def grep(mctx, x):
+    """``grep(regex)``
+    File contains the given regular expression.
+    """
+    pat = getstring(x, _("grep requires a pattern"))
+    r = re.compile(pat)
+    return [f for f in mctx.subset if r.search(mctx.ctx[f].data())]
+
 symbols = {
     'added': added,
     'binary': binary,
     'clean': clean,
     'deleted': deleted,
     'exec': exec_,
+    'grep': grep,
     'ignored': ignored,
     'hgignore': hgignore,
     'modified': modified,