# HG changeset patch # User Brodie Rao # Date 2010-09-17 15:21:02 # Node ID 40c40c6f20b84b5326e063560b69b82d07dba29a # Parent 381f131220adcb75bad12a58f6b1b61147c0f069 revset: handle re.compile() errors in grep() Raise error.ParseError instead of allowing re.error to bubble up. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -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 --git a/tests/test-revset b/tests/test-revset --- a/tests/test-revset +++ b/tests/test-revset @@ -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 --git a/tests/test-revset.out b/tests/test-revset.out --- a/tests/test-revset.out +++ b/tests/test-revset.out @@ -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