revset: handle re.compile() errors in grep()
Raise error.ParseError instead of allowing re.error to bubble up.
--- 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