Rev 4670: Fix bug #471193, allow tuples into the CHK code. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b2-471193-st-and-chk-map
John Arbash Meinel
john at arbash-meinel.com
Mon Nov 2 17:15:30 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b2-471193-st-and-chk-map
------------------------------------------------------------
revno: 4670
revision-id: john at arbash-meinel.com-20091102171520-8udwpeq12bnz1vkb
parent: pqm at pqm.ubuntu.com-20091031025119-p9o49k7xb50npphw
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b2-471193-st-and-chk-map
timestamp: Mon 2009-11-02 11:15:20 -0600
message:
Fix bug #471193, allow tuples into the CHK code.
Instead of raising a TypeError immediately, add a debug flag and only
raise TypeErrors if that flag is set. Sort of like how we did
ensure_unicode() for api changes.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2009-10-30 16:09:06 +0000
+++ b/NEWS 2009-11-02 17:15:20 +0000
@@ -31,6 +31,11 @@
they do occur. This fixes some causes of ``TooManyConcurrentRequests``
and similar errors. (Andrew Bennetts, #429747, #243391)
+* Reduce the strictness for StaticTuple, instead add a debug flag
+ ``-Dstatic_tuple`` which will change apis to be strict and raise errors.
+ This way, most users won't see failures, but developers can improve
+ internals. (John Arbash Meinel, #471193)
+
* TreeTransform.adjust_path updates the limbo paths of descendants of adjusted
files. (Aaron Bentley)
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2009-10-23 18:46:03 +0000
+++ b/bzrlib/chk_map.py 2009-11-02 17:15:20 +0000
@@ -720,6 +720,7 @@
:param bytes: The bytes of the node.
:param key: The key that the serialised node has.
"""
+ key = static_tuple.expect_static_tuple(key)
return _deserialise_leaf_node(bytes, key,
search_key_func=search_key_func)
@@ -1018,9 +1019,7 @@
:param key: The key that the serialised node has.
:return: An InternalNode instance.
"""
- if type(key) is not StaticTuple:
- raise AssertionError('deserialise should be called with a'
- ' StaticTuple not %s' % (type(key),))
+ key = static_tuple.expect_static_tuple(key)
return _deserialise_internal_node(bytes, key,
search_key_func=search_key_func)
=== modified file 'bzrlib/help_topics/en/debug-flags.txt'
--- a/bzrlib/help_topics/en/debug-flags.txt 2009-10-07 08:19:19 +0000
+++ b/bzrlib/help_topics/en/debug-flags.txt 2009-11-02 17:15:20 +0000
@@ -30,6 +30,7 @@
-Drelock Emit a message every time a branch or repository object is
unlocked then relocked the same way.
-Dsftp Trace SFTP internals.
+-Dstatic_tuple Error when a tuple is used where a StaticTuple is expected
-Dstream Trace fetch streams.
-Dstrict_locks Trace when OS locks are potentially used in a non-portable
manner.
=== modified file 'bzrlib/static_tuple.py'
--- a/bzrlib/static_tuple.py 2009-10-12 20:02:27 +0000
+++ b/bzrlib/static_tuple.py 2009-11-02 17:15:20 +0000
@@ -16,6 +16,8 @@
"""Interface thunk for a StaticTuple implementation."""
+from bzrlib import debug
+
try:
from bzrlib._static_tuple_c import StaticTuple
except ImportError, e:
@@ -23,3 +25,15 @@
osutils.failed_to_load_extension(e)
from bzrlib._static_tuple_py import StaticTuple
+
+def expect_static_tuple(obj):
+ """Check if the passed object is a StaticTuple.
+
+ Cast it if necessary, but if the 'static_tuple' debug flag is set, raise an
+ error instead.
+ """
+ if 'static_tuple' not in debug.debug_flags:
+ return StaticTuple.from_sequence(obj)
+ if type(obj) is not StaticTuple:
+ raise TypeError('We expected a StaticTuple not a %s' % (type(obj),))
+ return obj
=== modified file 'bzrlib/tests/test__static_tuple.py'
--- a/bzrlib/tests/test__static_tuple.py 2009-10-27 14:07:16 +0000
+++ b/bzrlib/tests/test__static_tuple.py 2009-11-02 17:15:20 +0000
@@ -22,6 +22,7 @@
from bzrlib import (
_static_tuple_py,
+ debug,
errors,
osutils,
static_tuple,
@@ -620,3 +621,28 @@
return
self.assertIs(static_tuple.StaticTuple,
self.module.StaticTuple)
+
+
+class TestEnsureStaticTuple(tests.TestCase):
+
+ def test_is_static_tuple(self):
+ st = static_tuple.StaticTuple('foo')
+ st2 = static_tuple.expect_static_tuple(st)
+ self.assertIs(st, st2)
+
+ def test_is_tuple(self):
+ t = ('foo',)
+ st = static_tuple.expect_static_tuple(t)
+ self.assertIsInstance(st, static_tuple.StaticTuple)
+ self.assertEqual(t, st)
+
+ def test_flagged_is_static_tuple(self):
+ debug.debug_flags.add('static_tuple')
+ st = static_tuple.StaticTuple('foo')
+ st2 = static_tuple.expect_static_tuple(st)
+ self.assertIs(st, st2)
+
+ def test_flagged_is_tuple(self):
+ debug.debug_flags.add('static_tuple')
+ t = ('foo',)
+ self.assertRaises(TypeError, static_tuple.expect_static_tuple, t)
More information about the bazaar-commits
mailing list