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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Plugin to force-reweave the inventory of a branch.
19
This makes sure that the inventory weave's DAG of ancestry is correct so that
20
attempts to fetch the branch over http, or certain merge operations cope
23
This is most likely needed if you have used fetch-ghosts from bzrlib to
24
resolve ghosts after a baz (or otherwise) import and you get bizarre behaviour
25
when either exporting over http or when merging from other translated branches.
28
from bzrlib.commands import Command
29
from bzrlib.weavefile import write_weave_v5 as w5
32
import bzrlib.progress
36
class cmd_force_reweave_inventory(Command):
37
"""Force-reweave the inventory in this branch.
39
The branch URL *MUST* be on the local filesystem."""
40
takes_args = ['branch_dir?']
42
def run(self, branch_dir="."):
43
branch = bzrlib.branch.Branch.open(branch_dir)
46
self._do_reweave(branch, branch_dir)
50
def _do_reweave(self, branch, branch_dir):
51
inventory_weave = branch.get_inventory_weave()
53
new_weave = bzrlib.weave.Weave()
55
pending = list(inventory_weave.iter_names())
57
progress = bzrlib.progress.ProgressBar()
60
index = pending.pop(0)
61
done = total - len(pending)
62
progress.update('re-weaving', done, total)
63
rev = branch.get_revision(index)
65
for parent in rev.parent_ids:
66
if parent in inventory_weave:
67
parents.append(parent)
68
unavailable = [p for p in parents if p not in new_weave]
69
if len(unavailable) == 0:
70
new_weave.add(index, parents, inventory_weave.get(index))
75
progress.update('Writing weave')
77
f = open(os.path.join(branch_dir, ".bzr", "inventory.weave"), "w")