bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.198.6
by Andrew Bennetts
Add bzr-check-chk. |
1 |
# Copyright (C) 2010-2011 Canonical Ltd
|
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
2 |
#
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
"""Check each CHK page to make sure it is in 'canonical' form.
|
|
18 |
||
19 |
"""
|
|
20 |
||
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
21 |
from __future__ import absolute_import |
22 |
||
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
23 |
from ... import ( |
24 |
controldir, |
|
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
25 |
commands, |
|
0.198.6
by Andrew Bennetts
Add bzr-check-chk. |
26 |
trace, |
27 |
transport, |
|
28 |
ui, |
|
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
29 |
)
|
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
30 |
from ...bzr import ( |
31 |
chk_map, |
|
32 |
groupcompress, |
|
33 |
)
|
|
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
34 |
|
35 |
||
36 |
class cmd_check_chk(commands.Command): |
|
37 |
"""Check the CHK pages for canonical form. |
|
38 |
"""
|
|
39 |
||
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
40 |
hidden = True |
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
41 |
takes_args = [] |
|
0.37.2
by John Arbash Meinel
Check both the id_to_entry and the parent_id_basename_to_file_id map. |
42 |
takes_options = ['directory', 'revision'] |
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
43 |
|
|
0.37.2
by John Arbash Meinel
Check both the id_to_entry and the parent_id_basename_to_file_id map. |
44 |
def run(self, directory='.', revision=None): |
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
45 |
wt, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch( |
|
0.37.1
by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory. |
46 |
directory) |
47 |
factory = groupcompress.make_pack_factory(False, False, 1) |
|
48 |
t = transport.get_transport('memory:///') |
|
49 |
vf = factory(t) |
|
50 |
self.add_cleanup(branch.lock_read().unlock) |
|
51 |
repo = branch.repository |
|
|
0.37.2
by John Arbash Meinel
Check both the id_to_entry and the parent_id_basename_to_file_id map. |
52 |
if revision is None or len(revision) == 0: |
53 |
inv_keys = repo.inventories.keys() |
|
54 |
inv_ids = [k[-1] for k in inv_keys] |
|
55 |
elif len(revision) == 1: |
|
56 |
inv_ids = [revision[0].as_revision_id(branch)] |
|
57 |
elif len(revision) == 2: |
|
58 |
g = repo.get_graph() |
|
59 |
r1 = revision[0].as_revision_id(branch) |
|
60 |
r2 = revision[1].as_revision_id(branch) |
|
61 |
inv_ids = g.find_unique_ancestors(r2, [r1]) |
|
|
7143.22.2
by Jelmer Vernooij
use more context libs for progress bars. |
62 |
with ui.ui_factory.nested_progress_bar() as pb: |
63 |
for idx, inv in enumerate(repo.iter_inventories(inv_ids)): |
|
64 |
pb.update('checking', idx, len(inv_ids)) |
|
65 |
d = dict(inv.id_to_entry.iteritems()) |
|
66 |
test_key = chk_map.CHKMap.from_dict( |
|
67 |
vf, d, maximum_size=inv.id_to_entry._root_node._maximum_size, |
|
68 |
key_width=inv.id_to_entry._root_node._key_width, |
|
69 |
search_key_func=inv.id_to_entry._search_key_func) |
|
70 |
if inv.id_to_entry.key() != test_key: |
|
71 |
trace.warning('Failed for id_to_entry inv: %s' |
|
72 |
% (inv.revision_id,)) |
|
73 |
pid = inv.parent_id_basename_to_file_id |
|
74 |
d = dict(pid.iteritems()) |
|
75 |
test_key = chk_map.CHKMap.from_dict( |
|
76 |
vf, d, maximum_size=pid._root_node._maximum_size, |
|
77 |
key_width=pid._root_node._key_width, |
|
78 |
search_key_func=pid._search_key_func) |
|
79 |
if pid.key() != test_key: |
|
80 |
trace.warning('Failed for parent_id_to_basename inv: %s' |
|
81 |
% (inv.revision_id,)) |