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