/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.198.7 by Andrew Bennetts
Add chk-used-by command.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.199.1 by Andrew Bennetts
Add chk-used-by command.
16
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
17
from __future__ import absolute_import
18
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
19
from ... import (
20
    controldir,
0.199.1 by Andrew Bennetts
Add chk-used-by command.
21
    static_tuple,
22
    )
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
23
from ...commands import (
0.199.1 by Andrew Bennetts
Add chk-used-by command.
24
    Command,
25
    )
26
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
27
0.199.1 by Andrew Bennetts
Add chk-used-by command.
28
class cmd_chk_used_by(Command):
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
29
0.199.1 by Andrew Bennetts
Add chk-used-by command.
30
    __doc__ = \
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
31
        """Find the inventories/revisions that reference a CHK."""
0.199.1 by Andrew Bennetts
Add chk-used-by command.
32
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
33
    hidden = True
0.199.1 by Andrew Bennetts
Add chk-used-by command.
34
    takes_args = ['key*']
35
    takes_options = ['directory']
36
37
    def run(self, key_list, directory=u'.'):
38
        key_list = [static_tuple.StaticTuple(k) for k in key_list]
39
        if len(key_list) > 1:
40
            key_list = frozenset(key_list)
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
41
        bd, relpath = controldir.ControlDir.open_containing(directory)
0.199.1 by Andrew Bennetts
Add chk-used-by command.
42
        repo = bd.find_repository()
43
        self.add_cleanup(repo.lock_read().unlock)
44
        inv_vf = repo.inventories
45
        all_invs = [k[-1] for k in inv_vf.keys()]
46
        # print len(all_invs)
47
        for inv in repo.iter_inventories(all_invs):
48
            if inv.id_to_entry.key() in key_list:
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
49
                self.outf.write(
50
                    'id_to_entry of %s -> %s\n' %
0.198.7 by Andrew Bennetts
Add chk-used-by command.
51
                    (inv.revision_id, inv.id_to_entry.key(),))
0.199.1 by Andrew Bennetts
Add chk-used-by command.
52
            if inv.parent_id_basename_to_file_id.key() in key_list:
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
53
                self.outf.write(
54
                    'parent_id_basename_to_file_id of %s -> %s\n' %
0.198.7 by Andrew Bennetts
Add chk-used-by command.
55
                    (inv.revision_id, inv.parent_id_basename_to_file_id.key(),))
0.199.1 by Andrew Bennetts
Add chk-used-by command.
56