changeset 12320:40c40c6f20b8 stable

revset: handle re.compile() errors in grep() Raise error.ParseError instead of allowing re.error to bubble up.
author Brodie Rao <brodie@bitheap.org>
date Fri, 17 Sep 2010 10:21:02 -0500
parents 381f131220ad
children 11db6fa2961e b0bb72460c44
files mercurial/revset.py tests/test-revset tests/test-revset.out
diffstat 3 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Mon Sep 20 15:33:39 2010 +0200
+++ b/mercurial/revset.py	Fri Sep 17 10:21:02 2010 -0500
@@ -268,7 +268,10 @@
     return l
 
 def grep(repo, subset, x):
-    gr = re.compile(getstring(x, _("grep wants a string")))
+    try:
+        gr = re.compile(getstring(x, _("grep wants a string")))
+    except re.error, e:
+        raise error.ParseError(_('invalid match pattern: %s') % e)
     l = []
     for r in subset:
         c = repo[r]
--- a/tests/test-revset	Mon Sep 20 15:33:39 2010 +0200
+++ b/tests/test-revset	Fri Sep 17 10:21:02 2010 -0500
@@ -110,6 +110,7 @@
 log 'file(b)'
 log 'follow()'
 log 'grep("issue\d+")'
+try 'grep("(")' # invalid regular expression
 log 'head()'
 log 'heads(6::)'
 log 'keyword(issue)'
--- a/tests/test-revset.out	Mon Sep 20 15:33:39 2010 +0200
+++ b/tests/test-revset.out	Fri Sep 17 10:21:02 2010 -0500
@@ -134,6 +134,9 @@
 9
 % log 'grep("issue\d+")'
 6
+% hg debugrevspec grep("(")
+('func', ('symbol', 'grep'), ('string', '('))
+hg: parse error: invalid match pattern: unbalanced parenthesis
 % log 'head()'
 0
 1