[PATCH stable] revset: handle re.compile() errors in grep()
Brodie Rao
brodie at bitheap.org
Fri Sep 17 10:21:29 CDT 2010
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1284736862 18000
# Branch stable
# Node ID a07a7a3ac405758eb4d08c54c4cc0fffb34147ae
# Parent fe20536c09d48b9fd6ae61f9a44e03b423379141
revset: handle re.compile() errors in grep()
Raise error.ParseError instead of allowing re.error to bubble up.
diff -r fe20536c09d4 -r a07a7a3ac405 mercurial/revset.py
--- a/mercurial/revset.py Thu Sep 16 16:05:00 2010 -0500
+++ b/mercurial/revset.py Fri Sep 17 10:21:02 2010 -0500
@@ -268,7 +268,10 @@ def keyword(repo, subset, x):
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]
diff -r fe20536c09d4 -r a07a7a3ac405 tests/test-revset
--- a/tests/test-revset Thu Sep 16 16:05:00 2010 -0500
+++ b/tests/test-revset Fri Sep 17 10:21:02 2010 -0500
@@ -110,6 +110,7 @@ log 'descendants(2 or 3)'
log 'file(b)'
log 'follow()'
log 'grep("issue\d+")'
+try 'grep("(")' # invalid regular expression
log 'head()'
log 'heads(6::)'
log 'keyword(issue)'
diff -r fe20536c09d4 -r a07a7a3ac405 tests/test-revset.out
--- a/tests/test-revset.out Thu Sep 16 16:05:00 2010 -0500
+++ b/tests/test-revset.out Fri Sep 17 10:21:02 2010 -0500
@@ -134,6 +134,9 @@ 8
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
More information about the Mercurial-devel
mailing list