revset: handle re.compile() errors in grep() stable
authorBrodie Rao <brodie@bitheap.org>
Fri, 17 Sep 2010 10:21:02 -0500
branchstable
changeset 12320 40c40c6f20b8
parent 12319 381f131220ad
child 12321 11db6fa2961e
child 12340 b0bb72460c44
revset: handle re.compile() errors in grep() Raise error.ParseError instead of allowing re.error to bubble up.
mercurial/revset.py
tests/test-revset
tests/test-revset.out
--- 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