/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.198.1 by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin.
1
# Copyright (C) 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
16
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
17
from ...controldir import ControlDir
18
from ...commands import Command
0.198.1 by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin.
19
20
21
class cmd_repo_has_key(Command):
22
    """Does a repo have a key?
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
23
0.198.1 by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin.
24
    e.g.::
25
26
      bzr repo-has-key texts FILE-ID REVISION-ID
27
      bzr repo-has-key revisions REVISION-ID
28
29
    It either prints "True" or "False", and terminates with exit code 0 or 1
30
    respectively.
31
    """
32
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
33
    hidden = True
0.198.1 by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin.
34
    takes_args = ['repo', 'key_parts*']
35
36
    def run(self, repo, key_parts_list=None):
37
        vf_name, key = key_parts_list[0], key_parts_list[1:]
6779.1.1 by Jelmer Vernooij
Merge lp:bzr-repodebug.
38
        bd = ControlDir.open(repo)
0.198.1 by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin.
39
        repo = bd.open_repository()
6779.1.3 by Jelmer Vernooij
Add some basic tests for repodebug.
40
        with repo.lock_read():
0.198.1 by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin.
41
            vf = getattr(repo, vf_name)
42
            key = tuple(key)
43
            if key in vf.get_parent_map([key]):
44
                self.outf.write("True\n")
45
                return 0
46
            else:
47
                self.outf.write("False\n")
48
                return 1