changeset 17368:01cc267fc105 stable

fileset: do not traceback on invalid grep pattern
author Patrick Mezard <patrick@mezard.eu>
date Wed, 15 Aug 2012 19:25:45 +0200
parents ce625185cfd9
children b360011a132d
files mercurial/fileset.py tests/test-fileset.t
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/fileset.py	Wed Aug 15 22:29:32 2012 +0200
+++ b/mercurial/fileset.py	Wed Aug 15 19:25:45 2012 +0200
@@ -256,8 +256,11 @@
     """``grep(regex)``
     File contains the given regular expression.
     """
-    pat = getstring(x, _("grep requires a pattern"))
-    r = re.compile(pat)
+    try:
+        # i18n: "grep" is a keyword
+        r = re.compile(getstring(x, _("grep requires a pattern")))
+    except re.error, e:
+        raise error.ParseError(_('invalid match pattern: %s') % e)
     return [f for f in mctx.existing() if r.search(mctx.ctx[f].data())]
 
 _units = dict(k=2**10, K=2**10, kB=2**10, KB=2**10,
--- a/tests/test-fileset.t	Wed Aug 15 22:29:32 2012 +0200
+++ b/tests/test-fileset.t	Wed Aug 15 19:25:45 2012 +0200
@@ -89,3 +89,11 @@
   $ fileset 'binary()'
   bin
 
+  $ fileset 'grep("b{1}")'
+  b2
+  c1
+  b1
+  $ fileset 'grep("missingparens(")'
+  hg: parse error: invalid match pattern: unbalanced parenthesis
+  [255]
+