/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

  • Committer: Jelmer Vernooij
  • Date: 2017-09-02 22:39:35 UTC
  • mfrom: (0.198.9 bzr-repodebug)
  • mto: This revision was merged to the branch mainline in revision 6786.
  • Revision ID: jelmer@jelmer.uk-20170902223935-tdznuv85ppvlmd8u
Merge lp:bzr-repodebug.

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 ... import (
 
22
    controldir,
 
23
    commands,
 
24
    trace,
 
25
    transport,
 
26
    ui,
 
27
    )
 
28
from ...bzr import (
 
29
    chk_map,
 
30
    groupcompress,
 
31
    )
 
32
 
 
33
 
 
34
class cmd_check_chk(commands.Command):
 
35
    """Check the CHK pages for canonical form.
 
36
    """
 
37
 
 
38
    hidden = True
 
39
    takes_args = []
 
40
    takes_options = ['directory', 'revision']
 
41
 
 
42
    def run(self, directory='.', revision=None):
 
43
        wt, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
 
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
 
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])
 
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'
 
71
                              % (inv.revision_id,))
 
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'
 
80
                              % (inv.revision_id,))
 
81