Rev 3771: First draft of a basic dump-btree command. in http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/dump_btree
John Arbash Meinel
john at arbash-meinel.com
Wed Oct 8 21:40:51 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.8-dev/dump_btree
------------------------------------------------------------
revno: 3771
revision-id: john at arbash-meinel.com-20081008204023-z1u32sjby509wl12
parent: pqm at pqm.ubuntu.com-20081008020104-e68hyxx45qo19nzx
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dump_btree
timestamp: Wed 2008-10-08 15:40:23 -0500
message:
First draft of a basic dump-btree command.
Does enough for what I need with pack-names files, but I'd like it to be a
bit more 'raw'.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2008-10-08 01:28:40 +0000
+++ b/NEWS 2008-10-08 20:40:23 +0000
@@ -7,6 +7,12 @@
IN DEVELOPMENT
--------------
+ IMPROVEMENTS:
+
+ * ``bzr dump-btree`` is a hidden command introduced to allow dumping
+ the contents of a compressed btree file. (John Arbash Meinel)
+
+
bzr 1.8rc1 2008-10-07
---------------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2008-10-02 17:28:44 +0000
+++ b/bzrlib/builtins.py 2008-10-08 20:40:23 +0000
@@ -255,7 +255,43 @@
' revision.')
rev_id = rev.as_revision_id(b)
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
-
+
+
+class cmd_dump_btree(Command):
+ """Dump the contents of a btree index file to disk.
+
+ This is useful because the pages are compressed, so they cannot be read
+ directly anymore.
+ """
+
+ # TODO: Do we want to dump the internal nodes as well?
+ # TODO: It would be nice to be able to dump the un-parsed information,
+ # rather than only going through iter_all_entries. However, this is
+ # good enough for a start
+ hidden = True
+ takes_args = ['path']
+
+ def run(self, path):
+ from bzrlib import btree_index
+
+ dirname, basename = osutils.split(path)
+ t = transport.get_transport(dirname)
+ try:
+ st = t.stat(basename)
+ except errors.TransportNotPossible:
+ # We can't stat, so we'll fake it because we have to do the 'get()'
+ # anyway.
+ bt = btree_index.BTreeGraphIndex(t, basename, None)
+ bytes = t.get_bytes(basename)
+ bt._file = cStringIO.StringIO(bytes)
+ bt._size = len(bytes)
+ else:
+ bt = btree_index.BTreeGraphIndex(t, basename, st.st_size)
+ for node in bt.iter_all_entries():
+ # Node is made up of:
+ # (index, key, value, [references])
+ self.outf.write('%s\n' % (node[1:],))
+
class cmd_remove_tree(Command):
"""Remove the working tree from a given branch/checkout.
=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py 2008-06-05 16:27:16 +0000
+++ b/bzrlib/tests/blackbox/__init__.py 2008-10-08 20:40:23 +0000
@@ -62,6 +62,7 @@
'bzrlib.tests.blackbox.test_conflicts',
'bzrlib.tests.blackbox.test_debug',
'bzrlib.tests.blackbox.test_diff',
+ 'bzrlib.tests.blackbox.test_dump_btree',
'bzrlib.tests.blackbox.test_exceptions',
'bzrlib.tests.blackbox.test_export',
'bzrlib.tests.blackbox.test_find_merge_base',
=== added file 'bzrlib/tests/blackbox/test_dump_btree.py'
--- a/bzrlib/tests/blackbox/test_dump_btree.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_dump_btree.py 2008-10-08 20:40:23 +0000
@@ -0,0 +1,61 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+"""Tests of the 'bzr dump-btree' command."""
+
+from bzrlib import (
+ btree_index,
+ tests,
+ )
+from bzrlib.tests import (
+ http_server,
+ )
+
+
+class TestDumpBtree(tests.TestCaseWithTransport):
+
+ def create_sample_btree_index(self):
+ builder = btree_index.BTreeBuilder(
+ reference_lists=1, key_elements=2)
+ builder.add_node(('test', 'key1'), 'value', ((('ref', 'entry'),),))
+ builder.add_node(('test', 'key2'), 'value2', ((('ref', 'entry2'),),))
+ builder.add_node(('test2', 'key3'), 'value3', ((('ref', 'entry3'),),))
+ out_f = builder.finish()
+ try:
+ self.build_tree_contents([('test.btree', out_f.read())])
+ finally:
+ out_f.close()
+
+ def test_dump_btree_smoke(self):
+ self.create_sample_btree_index()
+ out, err = self.run_bzr('dump-btree test.btree')
+ self.assertEqualDiff(
+ "(('test', 'key1'), 'value', ((('ref', 'entry'),),))\n"
+ "(('test', 'key2'), 'value2', ((('ref', 'entry2'),),))\n"
+ "(('test2', 'key3'), 'value3', ((('ref', 'entry3'),),))\n",
+ out)
+
+ def test_dump_btree_http_smoke(self):
+ self.transport_readonly_server = http_server.HttpServer
+ self.create_sample_btree_index()
+ url = self.get_readonly_url('test.btree')
+ out, err = self.run_bzr(['dump-btree', url])
+ self.assertEqualDiff(
+ "(('test', 'key1'), 'value', ((('ref', 'entry'),),))\n"
+ "(('test', 'key2'), 'value2', ((('ref', 'entry2'),),))\n"
+ "(('test2', 'key3'), 'value3', ((('ref', 'entry3'),),))\n",
+ out)
More information about the bazaar-commits
mailing list