88
from bzrlib.branch import Branch, find_branch, BZR_BRANCH_FORMAT_5
88
from bzrlib.branch import Branch, find_branch
89
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
89
90
from bzrlib.revfile import Revfile
90
91
from bzrlib.weave import Weave
91
92
from bzrlib.weavefile import read_weave, write_weave
113
114
note('starting upgrade of %s', os.path.abspath(self.base))
114
115
self._backup_control_dir()
115
note('starting upgrade')
116
self.pb = ui_factory.progress_bar()
117
if self.old_format == 4:
118
note('starting upgrade from format 4 to 5')
119
self._convert_to_weaves()
121
if self.old_format == 5:
122
note('starting upgrade from format 5 to 6')
123
self._convert_to_prefixed()
128
def _convert_to_prefixed(self):
129
from bzrlib.store import hash_prefix
130
for store_name in ["weaves", "revision-store"]:
131
note("adding prefixes to %s" % store_name)
132
store_dir = os.path.join(self.base, ".bzr", store_name)
133
for filename in os.listdir(store_dir):
134
if filename.endswith(".weave") or filename.endswith(".gz"):
135
file_id = os.path.splitext(filename)[0]
138
prefix_dir = os.path.join(store_dir, hash_prefix(file_id))
139
if not os.path.isdir(prefix_dir):
141
os.rename(os.path.join(store_dir, filename),
142
os.path.join(prefix_dir, filename))
143
self._set_new_format(BZR_BRANCH_FORMAT_6)
146
def _convert_to_weaves(self):
116
147
note('note: upgrade may be faster if all store files are ungzipped first')
117
self.pb = ui_factory.progress_bar()
118
148
if not os.path.isdir(self.base + '/.bzr/weaves'):
119
149
os.mkdir(self.base + '/.bzr/weaves')
120
150
self.inv_weave = Weave('inventory')
144
174
note(' %6d texts' % self.text_count)
145
175
self._write_all_weaves()
146
176
self._write_all_revs()
147
self._set_new_format()
148
177
self._cleanup_spare_files()
178
self._set_new_format(BZR_BRANCH_FORMAT_5)
151
181
def _open_branch(self):
152
182
self.branch = Branch.open_downlevel(self.base)
153
if self.branch._branch_format == 5:
154
note('this branch is already in the most current format')
183
self.old_format = self.branch._branch_format
184
if self.old_format == 6:
185
note('this branch is in the most current format')
156
if self.branch._branch_format != 4:
187
if self.old_format not in (4, 5):
157
188
raise BzrError("cannot upgrade from branch format %r" %
158
189
self.branch._branch_format)
162
def _set_new_format(self):
163
self.branch.put_controlfile('branch-format', BZR_BRANCH_FORMAT_5)
193
def _set_new_format(self, format):
194
self.branch.put_controlfile('branch-format', format)
166
197
def _cleanup_spare_files(self):