1
# Copyright (C) 2010-2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Check each CHK page to make sure it is in 'canonical' form.
34
class cmd_check_chk(commands.Command):
35
"""Check the CHK pages for canonical form.
40
takes_options = ['directory', 'revision']
42
def run(self, directory='.', revision=None):
43
wt, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
45
factory = groupcompress.make_pack_factory(False, False, 1)
46
t = transport.get_transport('memory:///')
48
self.add_cleanup(branch.lock_read().unlock)
49
repo = branch.repository
50
if revision is None or len(revision) == 0:
51
inv_keys = repo.inventories.keys()
52
inv_ids = [k[-1] for k in inv_keys]
53
elif len(revision) == 1:
54
inv_ids = [revision[0].as_revision_id(branch)]
55
elif len(revision) == 2:
57
r1 = revision[0].as_revision_id(branch)
58
r2 = revision[1].as_revision_id(branch)
59
inv_ids = g.find_unique_ancestors(r2, [r1])
60
pb = ui.ui_factory.nested_progress_bar()
61
self.add_cleanup(pb.finished)
62
for idx, inv in enumerate(repo.iter_inventories(inv_ids)):
63
pb.update('checking', idx, len(inv_ids))
64
d = dict(inv.id_to_entry.iteritems())
65
test_key = chk_map.CHKMap.from_dict(vf, d,
66
maximum_size=inv.id_to_entry._root_node._maximum_size,
67
key_width=inv.id_to_entry._root_node._key_width,
68
search_key_func=inv.id_to_entry._search_key_func)
69
if inv.id_to_entry.key() != test_key:
70
trace.warning('Failed for id_to_entry inv: %s'
72
pid = inv.parent_id_basename_to_file_id
73
d = dict(pid.iteritems())
74
test_key = chk_map.CHKMap.from_dict(vf, d,
75
maximum_size=pid._root_node._maximum_size,
76
key_width=pid._root_node._key_width,
77
search_key_func=pid._search_key_func)
78
if pid.key() != test_key:
79
trace.warning('Failed for parent_id_to_basename inv: %s'