/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-08 21:56:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3773.
  • Revision ID: john@arbash-meinel.com-20081008215612-y9v94tqxreqoangx
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
299
299
        # This is because the first page of every row starts with an
300
300
        # uncompressed header.
301
301
        bt, bytes = self._get_index_and_bytes(trans, basename)
302
 
        root_node = bt._get_root_node()
303
 
        for row_idx, row_start in enumerate(bt._row_offsets[:-1]):
304
 
            if row_idx == 0:
 
302
        for page_idx, page_start in enumerate(xrange(0, len(bytes),
 
303
                                                     btree_index._PAGE_SIZE)):
 
304
            page_end = min(page_start + btree_index._PAGE_SIZE, len(bytes))
 
305
            page_bytes = bytes[page_start:page_end]
 
306
            if page_idx == 0:
305
307
                self.outf.write('Root node:\n')
306
 
            elif row_idx < len(bt._row_lengths):
307
 
                self.outf.write('\nInternal Row %d:\n' % (row_idx,))
308
 
            else:
309
 
                self.outf.write('\nLeaf Row %d:\n' % (row_idx,))
310
 
            # Should we do something to ensure all pages are 'back-to-back'?
311
 
            # And we aren't skipping data in the middle?
312
 
            for page_idx in xrange(0, bt._row_lengths[row_idx]):
313
 
                start_idx = bt._row_offsets[row_idx] + page_idx
314
 
                start_offset = start_idx * btree_index._PAGE_SIZE
315
 
                finish_offset = min(start_offset + btree_index._PAGE_SIZE,
316
 
                                    len(bytes))
317
 
                page_bytes = bytes[start_offset:finish_offset]
318
 
                if row_idx == 0 and page_idx == 0:
319
 
                    header_end, data = bt._parse_header_from_bytes(page_bytes)
320
 
                    self.outf.write(page_bytes[:header_end])
321
 
                    page_bytes = data
322
 
                self.outf.write('\nPage %d (row: %d, offset: %d)\n'
323
 
                                % (start_idx, row_idx, page_idx))
324
 
                decomp_bytes = zlib.decompress(page_bytes)
325
 
                self.outf.write(decomp_bytes)
326
 
                self.outf.write('\n')
 
308
                header_end, data = bt._parse_header_from_bytes(page_bytes)
 
309
                self.outf.write(page_bytes[:header_end])
 
310
                page_bytes = data
 
311
            self.outf.write('\nPage %d\n' % (page_idx,))
 
312
            decomp_bytes = zlib.decompress(page_bytes)
 
313
            self.outf.write(decomp_bytes)
 
314
            self.outf.write('\n')
327
315
 
328
316
    def _dump_entries(self, trans, basename):
329
317
        try: