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) 2009-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.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
17 |
from ...controldir import ControlDir |
18 |
from ...commands import Command, Option |
|
19 |
from ... import errors |
|
20 |
from ...bzr.vf_search import PendingAncestryResult |
|
7143.21.1
by Jelmer Vernooij
Add WriteGroup contextmanager. |
21 |
from ...repository import WriteGroup |
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
22 |
from ...revision import NULL_REVISION |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
23 |
|
24 |
||
25 |
class cmd_fix_missing_keys_for_stacking(Command): |
|
26 |
"""Fix missing keys for stacking. |
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
27 |
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
28 |
This is the fixer script for <https://bugs.launchpad.net/bzr/+bug/354036>.
|
29 |
"""
|
|
30 |
||
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
31 |
hidden = True |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
32 |
takes_args = ['branch_url'] |
33 |
takes_options = [ |
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
34 |
Option( |
35 |
'dry-run', |
|
36 |
help="Show what would be done, but don't actually do anything."), |
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
37 |
]
|
38 |
||
39 |
def run(self, branch_url, dry_run=False): |
|
40 |
try: |
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
41 |
bd = ControlDir.open(branch_url) |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
42 |
b = bd.open_branch(ignore_fallbacks=True) |
43 |
except (errors.NotBranchError, errors.InvalidURL): |
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
44 |
raise errors.BzrCommandError( |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
45 |
"Not a branch or invalid URL: %s" % branch_url) |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
46 |
b.lock_read() |
47 |
try: |
|
48 |
url = b.get_stacked_on_url() |
|
49 |
except (errors.UnstackableRepositoryFormat, errors.NotStacked, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
50 |
errors.UnstackableBranchFormat): |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
51 |
b.unlock() |
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
52 |
raise errors.BzrCommandError("Not stacked: %s" % branch_url) |
53 |
raw_r = b.repository.controldir.open_repository() |
|
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
54 |
if dry_run: |
55 |
raw_r.lock_read() |
|
56 |
else: |
|
57 |
b.unlock() |
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
58 |
b = b.controldir.open_branch() |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
59 |
b.lock_read() |
60 |
raw_r.lock_write() |
|
61 |
try: |
|
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
62 |
revs = raw_r.all_revision_ids() |
63 |
rev_parents = raw_r.get_graph().get_parent_map(revs) |
|
64 |
needed = set() |
|
7479.2.1
by Jelmer Vernooij
Drop python2 support. |
65 |
map(needed.update, rev_parents.values()) |
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
66 |
needed.discard(NULL_REVISION) |
67 |
needed = set((rev,) for rev in needed) |
|
68 |
needed = needed - raw_r.inventories.keys() |
|
69 |
if not needed: |
|
70 |
# Nothing to see here.
|
|
71 |
return
|
|
72 |
self.outf.write("Missing inventories: %r\n" % needed) |
|
73 |
if dry_run: |
|
74 |
return
|
|
75 |
assert raw_r._format.network_name() == b.repository._format.network_name() |
|
76 |
stream = b.repository.inventories.get_record_stream( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
77 |
needed, 'topological', True) |
7143.21.1
by Jelmer Vernooij
Add WriteGroup contextmanager. |
78 |
with WriteGroup(raw_r): |
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
79 |
raw_r.inventories.insert_record_stream(stream) |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
80 |
finally: |
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
81 |
raw_r.unlock() |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
82 |
b.unlock() |
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
83 |
self.outf.write("Fixed: %s\n" % branch_url) |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
84 |
|
85 |
||
86 |
class cmd_mirror_revs_into(Command): |
|
87 |
"""Mirror all revs from one repo into another.""" |
|
88 |
||
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
89 |
hidden = True |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
90 |
takes_args = ['source', 'destination'] |
91 |
||
92 |
_see_also = ['fetch-all-records'] |
|
93 |
||
94 |
def run(self, source, destination): |
|
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
95 |
bd = ControlDir.open(source) |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
96 |
source_r = bd.open_branch().repository |
6779.1.1
by Jelmer Vernooij
Merge lp:bzr-repodebug. |
97 |
bd = ControlDir.open(destination) |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
98 |
target_r = bd.open_branch().repository |
6779.1.3
by Jelmer Vernooij
Add some basic tests for repodebug. |
99 |
with source_r.lock_read(), target_r.lock_write(): |
0.198.1
by Andrew Bennetts
Collate various hackish repair and debug plugins into one plugin. |
100 |
revs = [k[-1] for k in source_r.revisions.keys()] |
101 |
target_r.fetch( |
|
102 |
source_r, fetch_spec=PendingAncestryResult(revs, source_r)) |