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 |
|
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
18 |
from ...controldir import ControlDir |
19 |
from ...commands import Command, Option |
|
|
7143.11.1
by Jelmer Vernooij
Remove some unused imports. |
20 |
from ... import errors, urlutils |
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
21 |
|
22 |
||
23 |
class cmd_fetch_all_records(Command): |
|
24 |
__doc__ = """Fetch all records from another repository. |
|
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
25 |
|
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
26 |
This inserts every key from SOURCE_REPO into the target repository. Unlike
|
27 |
regular fetches this doesn't assume any relationship between keys (e.g.
|
|
28 |
that text X may be assumed to be present if inventory Y is present), so it
|
|
29 |
can be used to repair repositories where invariants about those
|
|
30 |
relationships have somehow been violated.
|
|
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 = ['source_repo'] |
35 |
takes_options = [ |
|
36 |
'directory', |
|
37 |
Option('dry-run', |
|
38 |
help="Show what would be done, but don't actually do anything."), |
|
39 |
]
|
|
40 |
||
41 |
def run(self, source_repo, directory=u'.', dry_run=False): |
|
42 |
try: |
|
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
43 |
source = ControlDir.open(source_repo).open_repository() |
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
44 |
except (errors.NotBranchError, urlutils.InvalidURL): |
45 |
print(u"Not a branch or invalid URL: %s" % source_repo, |
|
46 |
file=self.outf) |
|
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
47 |
return
|
48 |
||
49 |
try: |
|
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
50 |
target = ControlDir.open(directory).open_repository() |
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
51 |
except (errors.NotBranchError, urlutils.InvalidURL): |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
52 |
print(u"Not a branch or invalid URL: %s" % |
53 |
directory, file=self.outf) |
|
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
54 |
return
|
55 |
||
56 |
self.add_cleanup(source.lock_read().unlock) |
|
57 |
self.add_cleanup(target.lock_write().unlock) |
|
|
0.198.9
by John Arbash Meinel
Find the needed keys before starting the stream. |
58 |
|
59 |
# We need to find the keys to insert before we start the stream.
|
|
60 |
# Otherwise we'll be querying the target repo while we're trying to
|
|
61 |
# insert into it.
|
|
62 |
needed = [] |
|
63 |
for vf_name in ['signatures', 'texts', 'chk_bytes', 'inventories', |
|
64 |
'revisions']: |
|
65 |
vf = getattr(source, vf_name) |
|
66 |
target_vf = getattr(target, vf_name) |
|
67 |
source_keys = vf.keys() |
|
68 |
target_keys = target_vf.keys() |
|
69 |
keys = source_keys.difference(target_keys) |
|
70 |
needed.append((vf_name, keys)) |
|
71 |
||
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
72 |
def source_stream(): |
|
0.198.9
by John Arbash Meinel
Find the needed keys before starting the stream. |
73 |
for vf_name, keys in needed: |
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
74 |
vf = getattr(source, vf_name) |
75 |
yield (vf_name, vf.get_record_stream(keys, 'unordered', True)) |
|
|
0.198.9
by John Arbash Meinel
Find the needed keys before starting the stream. |
76 |
|
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
77 |
resume_tokens, missing_keys = target._get_sink().insert_stream( |
78 |
source_stream(), source._format, []) |
|
79 |
||
80 |
if not resume_tokens: |
|
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
81 |
print("Done.", file=self.outf) |
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
82 |
else: |
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
83 |
print("Missing keys!", missing_keys, file=self.outf) |