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