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