/brz/remove-bazaar

To get this branch, use:
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.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
21
from ... import (
22
    controldir,
0.37.1 by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory.
23
    commands,
0.198.6 by Andrew Bennetts
Add bzr-check-chk.
24
    trace,
25
    transport,
26
    ui,
0.37.1 by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory.
27
    )
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
28
from ...bzr import (
29
    chk_map,
30
    groupcompress,
31
    )
0.37.1 by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory.
32
33
34
class cmd_check_chk(commands.Command):
35
    """Check the CHK pages for canonical form.
36
    """
37
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
38
    hidden = True
0.37.1 by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory.
39
    takes_args = []
0.37.2 by John Arbash Meinel
Check both the id_to_entry and the parent_id_basename_to_file_id map.
40
    takes_options = ['directory', 'revision']
0.37.1 by John Arbash Meinel
Simplistic plugin that allows checking canonical form of every chk inventory.
41
0.37.2 by John Arbash Meinel
Check both the id_to_entry and the parent_id_basename_to_file_id map.
42
    def run(self, directory='.', revision=None):
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
43
        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.
44
            directory)
45
        factory = groupcompress.make_pack_factory(False, False, 1)
46
        t = transport.get_transport('memory:///')
47
        vf = factory(t)
48
        self.add_cleanup(branch.lock_read().unlock)
49
        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.
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:
56
            g = repo.get_graph()
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])
7143.22.2 by Jelmer Vernooij
use more context libs for progress bars.
60
        with ui.ui_factory.nested_progress_bar() as pb:
61
            for idx, inv in enumerate(repo.iter_inventories(inv_ids)):
62
                pb.update('checking', idx, len(inv_ids))
63
                d = dict(inv.id_to_entry.iteritems())
64
                test_key = chk_map.CHKMap.from_dict(
65
                    vf, d, maximum_size=inv.id_to_entry._root_node._maximum_size,
66
                    key_width=inv.id_to_entry._root_node._key_width,
67
                    search_key_func=inv.id_to_entry._search_key_func)
68
                if inv.id_to_entry.key() != test_key:
69
                    trace.warning('Failed for id_to_entry inv: %s'
70
                                  % (inv.revision_id,))
71
                pid = inv.parent_id_basename_to_file_id
72
                d = dict(pid.iteritems())
73
                test_key = chk_map.CHKMap.from_dict(
74
                    vf, d, maximum_size=pid._root_node._maximum_size,
75
                    key_width=pid._root_node._key_width,
76
                    search_key_func=pid._search_key_func)
77
                if pid.key() != test_key:
78
                    trace.warning('Failed for parent_id_to_basename inv: %s'
79
                                  % (inv.revision_id,))