1
# Copyright (C) 2009-2011 Canonical Ltd
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.
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.
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
18
from ...controldir import ControlDir
19
from ...commands import Command, Option
20
from ... import errors
21
from ...bzr.vf_search import PendingAncestryResult
22
from ...revision import NULL_REVISION
25
class cmd_fix_missing_keys_for_stacking(Command):
26
"""Fix missing keys for stacking.
28
This is the fixer script for <https://bugs.launchpad.net/bzr/+bug/354036>.
32
takes_args = ['branch_url']
35
help="Show what would be done, but don't actually do anything."),
38
def run(self, branch_url, dry_run=False):
40
bd = ControlDir.open(branch_url)
41
b = bd.open_branch(ignore_fallbacks=True)
42
except (errors.NotBranchError, errors.InvalidURL):
43
raise errors.BzrCommandError(
44
"Not a branch or invalid URL: %s" % branch_url)
47
url = b.get_stacked_on_url()
48
except (errors.UnstackableRepositoryFormat, errors.NotStacked,
49
errors.UnstackableBranchFormat):
51
raise errors.BzrCommandError("Not stacked: %s" % branch_url)
52
raw_r = b.repository.controldir.open_repository()
57
b = b.controldir.open_branch()
61
revs = raw_r.all_revision_ids()
62
rev_parents = raw_r.get_graph().get_parent_map(revs)
64
map(needed.update, rev_parents.itervalues())
65
needed.discard(NULL_REVISION)
66
needed = set((rev,) for rev in needed)
67
needed = needed - raw_r.inventories.keys()
69
# Nothing to see here.
71
self.outf.write("Missing inventories: %r\n" % needed)
74
assert raw_r._format.network_name() == b.repository._format.network_name()
75
stream = b.repository.inventories.get_record_stream(needed, 'topological', True)
76
raw_r.start_write_group()
78
raw_r.inventories.insert_record_stream(stream)
80
raw_r.abort_write_group()
83
raw_r.commit_write_group()
87
self.outf.write("Fixed: %s\n" % branch_url)
90
class cmd_mirror_revs_into(Command):
91
"""Mirror all revs from one repo into another."""
94
takes_args = ['source', 'destination']
96
_see_also = ['fetch-all-records']
98
def run(self, source, destination):
99
bd = ControlDir.open(source)
100
source_r = bd.open_branch().repository
101
bd = ControlDir.open(destination)
102
target_r = bd.open_branch().repository
104
target_r.lock_write()
106
revs = [k[-1] for k in source_r.revisions.keys()]
108
source_r, fetch_spec=PendingAncestryResult(revs, source_r))