Rev 3817: Change child_child to use _dump_tree, in http://bzr.arbash-meinel.com/branches/bzr/brisbane/prefix
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 7 19:38:21 GMT 2009
At http://bzr.arbash-meinel.com/branches/bzr/brisbane/prefix
------------------------------------------------------------
revno: 3817
revision-id: john at arbash-meinel.com-20090107193803-prc4a4jairkgjczp
parent: john at arbash-meinel.com-20090107191812-n73bqf8o0a8igwzp
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: prefix
timestamp: Wed 2009-01-07 13:38:03 -0600
message:
Change child_child to use _dump_tree,
update _dump_tree to allow suppressing the node keys.
Since it often doesn't matter for the tests.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2009-01-07 19:10:21 +0000
+++ b/bzrlib/chk_map.py 2009-01-07 19:38:03 +0000
@@ -113,26 +113,33 @@
stream = self._store.get_record_stream([key], 'unordered', True)
return stream.next().get_bytes_as('fulltext')
- def _dump_tree(self):
+ def _dump_tree(self, include_keys=True):
"""Return the tree in a string representation."""
self._ensure_root()
- res = self._dump_tree_node(self._root_node, prefix='', indent='')
+ res = self._dump_tree_node(self._root_node, prefix='', indent='',
+ include_keys=include_keys)
res.append('') # Give a trailing '\n'
return '\n'.join(res)
- def _dump_tree_node(self, node, prefix, indent):
+ def _dump_tree_node(self, node, prefix, indent, include_keys=True):
"""For this node and all children, generate a string representation."""
result = []
- node_key = node.key()
- if node_key is not None:
- node_key = node_key[0]
- result.append('%s%r %s %s' % (indent, prefix, node.__class__.__name__,
- node_key))
+ if not include_keys:
+ key_str = ''
+ else:
+ node_key = node.key()
+ if node_key is not None:
+ key_str = ' %s' % (node_key[0],)
+ else:
+ key_str = ' None'
+ result.append('%s%r %s%s' % (indent, prefix, node.__class__.__name__,
+ key_str))
if isinstance(node, InternalNode):
# Trigger all child nodes to get loaded
list(node._iter_nodes(self._store))
for prefix, sub in sorted(node._items.iteritems()):
- result.extend(self._dump_tree_node(sub, prefix, indent + ' '))
+ result.extend(self._dump_tree_node(sub, prefix, indent + ' ',
+ include_keys=include_keys))
else:
for key, value in sorted(node._items.iteritems()):
result.append(' %r %r' % (key, value))
=== modified file 'bzrlib/tests/test_chk_map.py'
--- a/bzrlib/tests/test_chk_map.py 2009-01-07 19:18:12 +0000
+++ b/bzrlib/tests/test_chk_map.py 2009-01-07 19:38:03 +0000
@@ -647,7 +647,7 @@
# aab - common altered
# b - basis only
# at - target only
- # we expect:
+ # we expect:
# aaa to be not loaded (later test)
# aab, b, at to be returned.
# basis splits at byte 0,1,2, aaa is commonb is basis only
@@ -671,7 +671,7 @@
# aab - common altered
# b - basis only
# at - target only
- # we expect:
+ # we expect:
# aaa to be not loaded
# aaa not to be in result.
basis_dict = {('aaa',): 'foo bar',
@@ -1089,7 +1089,7 @@
keys = list(node.serialise(chk_bytes))
child_key = child.serialise(chk_bytes)[0]
self.assertEqual(
- [child_key, ('sha1:db23b260c2bf46bf7446c39f91668900a2491610',)],
+ [child_key, ('sha1:72dda40e7c70d00cde178f6f79560d36f3264ba5',)],
keys)
# We should be able to access deserialised content.
bytes = self.read_bytes(chk_bytes, keys[1])
@@ -1181,8 +1181,14 @@
def test_map_to_child_child_splits_new(self):
chkmap = self._get_map({('k1',):'foo', ('k22',):'bar'}, maximum_size=10)
# Check for the canonical root value for this tree:
- self.assertEqual(('sha1:d3f06fc03d8f50845894d8d04cc5a3f47e62948d',),
- chkmap._root_node)
+ self.assertEqualDiff("'' InternalNode\n"
+ " 'k1' LeafNode\n"
+ " ('k1',) 'foo'\n"
+ " 'k2' LeafNode\n"
+ " ('k22',) 'bar'\n"
+ , chkmap._dump_tree(include_keys=False))
+ # _dump_tree pages everything in, so reload using just the root
+ chkmap = CHKMap(chkmap._store, chkmap._root_node)
chkmap._ensure_root()
node = chkmap._root_node
# Ensure test validity: nothing paged in below the root.
@@ -1217,9 +1223,16 @@
child_key = child._key
k22_key = child._items['k22']._key
k23_key = child._items['k23']._key
- self.assertEqual([k22_key, k23_key, child_key, keys[-1]], keys)
- self.assertEqual(('sha1:d68cd97c95e847d3dc58c05537aa5fdcdf2cf5da',),
- keys[-1])
+ self.assertEqual([k22_key, k23_key, child_key, node.key()], keys)
+ self.assertEqualDiff("'' InternalNode\n"
+ " 'k1' LeafNode\n"
+ " ('k1',) 'foo'\n"
+ " 'k2' InternalNode\n"
+ " 'k22' LeafNode\n"
+ " ('k22',) 'bar'\n"
+ " 'k23' LeafNode\n"
+ " ('k23',) 'quux'\n"
+ , chkmap._dump_tree(include_keys=False))
def test_unmap_k23_from_k1_k22_k23_gives_k1_k22_tree_new(self):
chkmap = self._get_map(
@@ -1257,7 +1270,7 @@
chkmap._ensure_root()
node = chkmap._root_node
k2_ptr = node._items['k2']
- # unmapping k21 should give us a root, with k22 and k23 as direct
+ # unmapping k1 should give us a root, with k22 and k23 as direct
# children, and should not have needed to page in the subtree.
result = node.unmap(chkmap._store, ('k1',))
self.assertEqual(k2_ptr, result)
@@ -1275,7 +1288,7 @@
# otherwise as soon as the sum of serialised values exceeds the split threshold
# we know we can't combine - stop.
# unmap -> key return data - space in node, common prefix length? and key count
-# internal:
+# internal:
# variable length prefixes? -> later start with fixed width to get something going
# map -> fits - update pointer to leaf
# return [prefix and node] - seems sound.
@@ -1290,7 +1303,7 @@
# map - unmap - if empty, use empty leafnode (avoids special cases in driver
# code)
# map inits as empty leafnode.
-# tools:
+# tools:
# visualiser
@@ -1301,7 +1314,7 @@
# single byte fanout - A,B, AA,AB,AC,AD, BA
# build order's:
# BA
-# AB - split, but we want to end up with AB, BA, in one node, with
+# AB - split, but we want to end up with AB, BA, in one node, with
# 1-4K get0
More information about the bazaar-commits
mailing list