256
257
rev_id = rev.as_revision_id(b)
257
258
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
261
class cmd_dump_btree(Command):
262
"""Dump the contents of a btree index file to stdout.
264
PATH is a btree index file, it can be any URL. This includes things like
265
.bzr/repository/pack-names, or .bzr/repository/indices/a34b3a...ca4a4.iix
267
By default, the tuples stored in the index file will be displayed. With
268
--raw, we will uncompress the pages, but otherwise display the raw bytes
272
# TODO: Do we want to dump the internal nodes as well?
273
# TODO: It would be nice to be able to dump the un-parsed information,
274
# rather than only going through iter_all_entries. However, this is
275
# good enough for a start
277
encoding_type = 'exact'
278
takes_args = ['path']
279
takes_options = [Option('raw', help='Write the uncompressed bytes out,'
280
' rather than the parsed tuples.'),
283
def run(self, path, raw=False):
284
dirname, basename = osutils.split(path)
285
t = transport.get_transport(dirname)
287
self._dump_raw_bytes(t, basename)
289
self._dump_entries(t, basename)
291
def _get_index_and_bytes(self, trans, basename):
292
"""Create a BTreeGraphIndex and raw bytes."""
293
bt = btree_index.BTreeGraphIndex(trans, basename, None)
294
bytes = trans.get_bytes(basename)
295
bt._file = cStringIO.StringIO(bytes)
296
bt._size = len(bytes)
299
def _dump_raw_bytes(self, trans, basename):
302
# We need to parse at least the root node.
303
# This is because the first page of every row starts with an
304
# uncompressed header.
305
bt, bytes = self._get_index_and_bytes(trans, basename)
306
for page_idx, page_start in enumerate(xrange(0, len(bytes),
307
btree_index._PAGE_SIZE)):
308
page_end = min(page_start + btree_index._PAGE_SIZE, len(bytes))
309
page_bytes = bytes[page_start:page_end]
311
self.outf.write('Root node:\n')
312
header_end, data = bt._parse_header_from_bytes(page_bytes)
313
self.outf.write(page_bytes[:header_end])
315
self.outf.write('\nPage %d\n' % (page_idx,))
316
decomp_bytes = zlib.decompress(page_bytes)
317
self.outf.write(decomp_bytes)
318
self.outf.write('\n')
320
def _dump_entries(self, trans, basename):
322
st = trans.stat(basename)
323
except errors.TransportNotPossible:
324
# We can't stat, so we'll fake it because we have to do the 'get()'
326
bt, _ = self._get_index_and_bytes(trans, basename)
328
bt = btree_index.BTreeGraphIndex(trans, basename, st.st_size)
329
for node in bt.iter_all_entries():
330
# Node is made up of:
331
# (index, key, value, [references])
332
self.outf.write('%s\n' % (node[1:],))
260
335
class cmd_remove_tree(Command):
261
336
"""Remove the working tree from a given branch/checkout.