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_fix(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)
51
def _do_reweave(branch, branch_dir):
52
inventory_weave = branch._get_inventory_weave()
54
new_weave = bzrlib.weave.Weave()
56
pending = list(inventory_weave.iter_names())
58
progress = bzrlib.progress.ProgressBar()
61
index = pending.pop(0)
62
done = total - len(pending)
63
progress.update('re-weaving', done, total)
64
rev = branch.get_revision(index)
66
for parent in rev.parent_ids:
67
if parent in inventory_weave:
68
parents.append(parent)
69
unavailable = [p for p in parents if p not in new_weave]
70
if len(unavailable) == 0:
71
new_weave.add(index, parents, inventory_weave.get(index))
76
progress.update('Writing weave')
78
out_file_name = os.path.join(branch_dir, ".bzr", "inventory.weave")
79
f = open(out_file_name+".tmp", "w")
82
os.rename(out_file_name+".tmp", out_file_name)