At http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/dump_btree
------------------------------------------------------------
revno: 3773
revision-id: [EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: John Arbash Meinel <[EMAIL PROTECTED]>
branch nick: dump_btree
timestamp: Wed 2008-10-08 16:56:12 -0500
message:
Simplify the --raw mode.
I didn't realize, but the only node that is special cased is the 'root' node,
and to read it, you actually have to parse it directly, because the
compressed bytes start immediately after the end of the header, rather than
having any padding before the zlib bytes.
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-10-08 21:51:37 +0000
+++ b/bzrlib/builtins.py 2008-10-08 21:56:12 +0000
@@ -299,31 +299,19 @@
# This is because the first page of every row starts with an
# uncompressed header.
bt, bytes = self._get_index_and_bytes(trans, basename)
- root_node = bt._get_root_node()
- for row_idx, row_start in enumerate(bt._row_offsets[:-1]):
- if row_idx == 0:
+ for page_idx, page_start in enumerate(xrange(0, len(bytes),
+ btree_index._PAGE_SIZE)):
+ page_end = min(page_start + btree_index._PAGE_SIZE, len(bytes))
+ page_bytes = bytes[page_start:page_end]
+ if page_idx == 0:
self.outf.write('Root node:\n')
- elif row_idx < len(bt._row_lengths):
- self.outf.write('\nInternal Row %d:\n' % (row_idx,))
- else:
- self.outf.write('\nLeaf Row %d:\n' % (row_idx,))
- # Should we do something to ensure all pages are 'back-to-back'?
- # And we aren't skipping data in the middle?
- for page_idx in xrange(0, bt._row_lengths[row_idx]):
- start_idx = bt._row_offsets[row_idx] + page_idx
- start_offset = start_idx * btree_index._PAGE_SIZE
- finish_offset = min(start_offset + btree_index._PAGE_SIZE,
- len(bytes))
- page_bytes = bytes[start_offset:finish_offset]
- if row_idx == 0 and page_idx == 0:
- header_end, data = bt._parse_header_from_bytes(page_bytes)
- self.outf.write(page_bytes[:header_end])
- page_bytes = data
- self.outf.write('\nPage %d (row: %d, offset: %d)\n'
- % (start_idx, row_idx, page_idx))
- decomp_bytes = zlib.decompress(page_bytes)
- self.outf.write(decomp_bytes)
- self.outf.write('\n')
+ header_end, data = bt._parse_header_from_bytes(page_bytes)
+ self.outf.write(page_bytes[:header_end])
+ page_bytes = data
+ self.outf.write('\nPage %d\n' % (page_idx,))
+ decomp_bytes = zlib.decompress(page_bytes)
+ self.outf.write(decomp_bytes)
+ self.outf.write('\n')
def _dump_entries(self, trans, basename):
try:
=== modified file 'bzrlib/tests/blackbox/test_dump_btree.py'
--- a/bzrlib/tests/blackbox/test_dump_btree.py 2008-10-08 21:51:37 +0000
+++ b/bzrlib/tests/blackbox/test_dump_btree.py 2008-10-08 21:56:12 +0000
@@ -71,7 +71,7 @@
'len=3\n'
'row_lengths=1\n'
'\n'
- 'Page 0 (row: 0, offset: 0)\n'
+ 'Page 0\n'
'type=leaf\n'
'test\0key1\0ref\0entry\0value\n'
'test\0key2\0ref\0entry2\0value2\n'
--
bazaar-commits mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/bazaar-commits