Merge lp:~jelmer/brz/move-errors-lazy-regex into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6732
Proposed branch: lp:~jelmer/brz/move-errors-lazy-regex
Merge into: lp:brz
Diff against target: 153 lines (+24/-20)
7 files modified
breezy/builtins.py (+2/-1)
breezy/errors.py (+0/-8)
breezy/globbing.py (+2/-2)
breezy/lazy_regex.py (+9/-1)
breezy/tests/test_errors.py (+0/-5)
breezy/tests/test_globbing.py (+2/-2)
breezy/tests/test_lazy_regex.py (+9/-1)
To merge this branch: bzr merge lp:~jelmer/brz/move-errors-lazy-regex
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+327181@code.launchpad.net

Commit message

Move InvalidPattern error to breezy.lazy_regex.

Description of the change

Move InvalidPattern error to breezy.lazy_regex.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Seems sane.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/builtins.py'
--- breezy/builtins.py 2017-06-24 14:00:24 +0000
+++ breezy/builtins.py 2017-07-11 00:02:51 +0000
@@ -40,6 +40,7 @@
40 errors,40 errors,
41 globbing,41 globbing,
42 hooks,42 hooks,
43 lazy_regex,
43 log,44 log,
44 merge as _mod_merge,45 merge as _mod_merge,
45 merge_directive,46 merge_directive,
@@ -3190,7 +3191,7 @@
3190 'Invalid ignore patterns found. %s',3191 'Invalid ignore patterns found. %s',
3191 bad_patterns_count) % bad_patterns)3192 bad_patterns_count) % bad_patterns)
3192 ui.ui_factory.show_error(msg)3193 ui.ui_factory.show_error(msg)
3193 raise errors.InvalidPattern('')3194 raise lazy_regex.InvalidPattern('')
3194 for name_pattern in name_pattern_list:3195 for name_pattern in name_pattern_list:
3195 if (name_pattern[0] == '/' or3196 if (name_pattern[0] == '/' or
3196 (len(name_pattern) > 1 and name_pattern[1] == ':')):3197 (len(name_pattern) > 1 and name_pattern[1] == ':')):
31973198
=== modified file 'breezy/errors.py'
--- breezy/errors.py 2017-07-04 20:03:11 +0000
+++ breezy/errors.py 2017-07-11 00:02:51 +0000
@@ -3181,14 +3181,6 @@
3181 'E.g. brz whoami "Your Name <name@example.com>"')3181 'E.g. brz whoami "Your Name <name@example.com>"')
31823182
31833183
3184class InvalidPattern(BzrError):
3185
3186 _fmt = ('Invalid pattern(s) found. %(msg)s')
3187
3188 def __init__(self, msg):
3189 self.msg = msg
3190
3191
3192class RecursiveBind(BzrError):3184class RecursiveBind(BzrError):
31933185
3194 _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '3186 _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
31953187
=== modified file 'breezy/globbing.py'
--- breezy/globbing.py 2017-05-22 00:56:52 +0000
+++ breezy/globbing.py 2017-07-11 00:02:51 +0000
@@ -242,7 +242,7 @@
242 match = regex.match(filename)242 match = regex.match(filename)
243 if match:243 if match:
244 return patterns[match.lastindex -1]244 return patterns[match.lastindex -1]
245 except errors.InvalidPattern as e:245 except lazy_regex.InvalidPattern as e:
246 # We can't show the default e.msg to the user as thats for246 # We can't show the default e.msg to the user as thats for
247 # the combined pattern we sent to regex. Instead we indicate to247 # the combined pattern we sent to regex. Instead we indicate to
248 # the user that an ignore file needs fixing.248 # the user that an ignore file needs fixing.
@@ -286,7 +286,7 @@
286 try:286 try:
287 re_obj = lazy_regex.lazy_compile(tpattern, re.UNICODE)287 re_obj = lazy_regex.lazy_compile(tpattern, re.UNICODE)
288 re_obj.search("") # force compile288 re_obj.search("") # force compile
289 except errors.InvalidPattern as e:289 except lazy_regex.InvalidPattern as e:
290 result = False290 result = False
291 return result291 return result
292292
293293
=== modified file 'breezy/lazy_regex.py'
--- breezy/lazy_regex.py 2017-05-22 00:56:52 +0000
+++ breezy/lazy_regex.py 2017-07-11 00:02:51 +0000
@@ -31,6 +31,14 @@
31from . import errors31from . import errors
3232
3333
34class InvalidPattern(errors.BzrError):
35
36 _fmt = ('Invalid pattern(s) found. %(msg)s')
37
38 def __init__(self, msg):
39 self.msg = msg
40
41
34class LazyRegex(object):42class LazyRegex(object):
35 """A proxy around a real regex, which won't be compiled until accessed."""43 """A proxy around a real regex, which won't be compiled until accessed."""
3644
@@ -71,7 +79,7 @@
71 except re.error as e:79 except re.error as e:
72 # raise InvalidPattern instead of re.error as this gives a80 # raise InvalidPattern instead of re.error as this gives a
73 # cleaner message to the user.81 # cleaner message to the user.
74 raise errors.InvalidPattern('"' + args[0] + '" ' +str(e))82 raise InvalidPattern('"' + args[0] + '" ' +str(e))
7583
76 def __getstate__(self):84 def __getstate__(self):
77 """Return the state to use when pickling."""85 """Return the state to use when pickling."""
7886
=== modified file 'breezy/tests/test_errors.py'
--- breezy/tests/test_errors.py 2017-06-10 18:39:27 +0000
+++ breezy/tests/test_errors.py 2017-07-11 00:02:51 +0000
@@ -619,11 +619,6 @@
619 err = errors.NotBranchError('path', controldir=FakeBzrDir())619 err = errors.NotBranchError('path', controldir=FakeBzrDir())
620 self.assertEqual('Not a branch: "path": NotBranchError.', str(err))620 self.assertEqual('Not a branch: "path": NotBranchError.', str(err))
621621
622 def test_invalid_pattern(self):
623 error = errors.InvalidPattern('Bad pattern msg.')
624 self.assertEqualDiff("Invalid pattern(s) found. Bad pattern msg.",
625 str(error))
626
627 def test_recursive_bind(self):622 def test_recursive_bind(self):
628 error = errors.RecursiveBind('foo_bar_branch')623 error = errors.RecursiveBind('foo_bar_branch')
629 msg = ('Branch "foo_bar_branch" appears to be bound to itself. '624 msg = ('Branch "foo_bar_branch" appears to be bound to itself. '
630625
=== modified file 'breezy/tests/test_globbing.py'
--- breezy/tests/test_globbing.py 2017-06-04 18:09:30 +0000
+++ breezy/tests/test_globbing.py 2017-07-11 00:02:51 +0000
@@ -17,7 +17,7 @@
1717
18import re18import re
1919
20from .. import errors20from .. import errors, lazy_regex
21from ..globbing import (21from ..globbing import (
22 Globster,22 Globster,
23 ExceptionGlobster,23 ExceptionGlobster,
@@ -316,7 +316,7 @@
316 """Ensure that globster handles bad patterns cleanly."""316 """Ensure that globster handles bad patterns cleanly."""
317 patterns = [u'RE:[', u'/home/foo', u'RE:*.cpp']317 patterns = [u'RE:[', u'/home/foo', u'RE:*.cpp']
318 g = Globster(patterns)318 g = Globster(patterns)
319 e = self.assertRaises(errors.InvalidPattern, g.match, 'filename')319 e = self.assertRaises(lazy_regex.InvalidPattern, g.match, 'filename')
320 self.assertContainsRe(e.msg,320 self.assertContainsRe(e.msg,
321 "File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)321 "File.*ignore.*contains error.*RE:\[.*RE:\*\.cpp", flags=re.DOTALL)
322322
323323
=== modified file 'breezy/tests/test_lazy_regex.py'
--- breezy/tests/test_lazy_regex.py 2017-05-22 00:56:52 +0000
+++ breezy/tests/test_lazy_regex.py 2017-07-11 00:02:51 +0000
@@ -26,6 +26,14 @@
26 )26 )
2727
2828
29class ErrorTests(tests.TestCase):
30
31 def test_invalid_pattern(self):
32 error = lazy_regex.InvalidPattern('Bad pattern msg.')
33 self.assertEqualDiff("Invalid pattern(s) found. Bad pattern msg.",
34 str(error))
35
36
29class InstrumentedLazyRegex(lazy_regex.LazyRegex):37class InstrumentedLazyRegex(lazy_regex.LazyRegex):
30 """Keep track of actions on the lazy regex"""38 """Keep track of actions on the lazy regex"""
3139
@@ -71,7 +79,7 @@
71 p = lazy_regex.lazy_compile('RE:[')79 p = lazy_regex.lazy_compile('RE:[')
72 # As p.match is lazy, we make it into a lambda so its handled80 # As p.match is lazy, we make it into a lambda so its handled
73 # by assertRaises correctly.81 # by assertRaises correctly.
74 e = self.assertRaises(errors.InvalidPattern, lambda: p.match('foo'))82 e = self.assertRaises(lazy_regex.InvalidPattern, lambda: p.match('foo'))
75 self.assertEqual(e.msg, '"RE:[" unexpected end of regular expression')83 self.assertEqual(e.msg, '"RE:[" unexpected end of regular expression')
7684
7785

Subscribers

People subscribed via source and target branches