[PATCH] hg grep: handle re.compile errors & update tests/test-grep
Giorgos Keramidas
keramida at ceid.upatras.gr
Mon Jul 9 09:41:53 CDT 2007
# HG changeset patch
# User Giorgos Keramidas <keramida at ceid.upatras.gr>
# Date 1183992074 -10800
# Node ID 1ba70cdb3e1cc18670da8e8b75d08c9c54f893a7
# Parent 34619ae215004ce8ff4927527d9d00d89f6482c6
hg grep: handle re.compile errors & update tests/test-grep
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1105,7 +1105,11 @@ def grep(ui, repo, pattern, *pats, **opt
reflags = 0
if opts['ignore_case']:
reflags |= re.I
- regexp = re.compile(pattern, reflags)
+ try:
+ regexp = re.compile(pattern, reflags)
+ except Exception, inst:
+ ui.warn(_("grep: invalid match pattern: %s!\n") % inst)
+ return None
sep, eol = ':', '\n'
if opts['print0']:
sep = eol = '\0'
diff --git a/tests/test-grep b/tests/test-grep
--- a/tests/test-grep
+++ b/tests/test-grep
@@ -17,6 +17,8 @@ head -n 3 port > port1
head -n 3 port > port1
mv port1 port
hg commit -m 4 -u spam -d '4 0'
+echo % pattern error
+hg grep '**test**'
echo % simple
hg grep port port
echo % all
diff --git a/tests/test-grep.out b/tests/test-grep.out
--- a/tests/test-grep.out
+++ b/tests/test-grep.out
@@ -1,3 +1,5 @@
+% pattern error
+grep: invalid match pattern: nothing to repeat!
% simple
port:4:export
port:4:vaportight
More information about the Mercurial-devel
mailing list