/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/repodebug/check_chk.py

[merge] robertc's integration, updated tests to check for retcode=3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010-2011 Canonical Ltd
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
 
 
21
 
from __future__ import absolute_import
22
 
 
23
 
from ... import (
24
 
    controldir,
25
 
    commands,
26
 
    trace,
27
 
    transport,
28
 
    ui,
29
 
    )
30
 
from ...bzr import (
31
 
    chk_map,
32
 
    groupcompress,
33
 
    )
34
 
 
35
 
 
36
 
class cmd_check_chk(commands.Command):
37
 
    """Check the CHK pages for canonical form.
38
 
    """
39
 
 
40
 
    hidden = True
41
 
    takes_args = []
42
 
    takes_options = ['directory', 'revision']
43
 
 
44
 
    def run(self, directory='.', revision=None):
45
 
        wt, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
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
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])
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,))