109
112
def convert(self):
110
113
enable_default_logging()
114
self._backup_control_dir()
111
115
self.pb = ProgressBar()
116
if not os.path.isdir('.bzr/weaves'):
117
os.mkdir('.bzr/weaves')
112
118
self.inv_weave = Weave('__inventory')
113
119
self.anc_weave = Weave('__ancestry')
114
120
self.ancestries = {}
115
121
# holds in-memory weaves for all files
116
122
self.text_weaves = {}
117
123
self.branch = Branch('.', relax_version_check=True)
118
rev_history = self.branch.revision_history()
124
self._convert_working_inv()
125
rev_history = self.branch.revision_history()[:300]
119
126
# to_read is a stack holding the revisions we still need to process;
120
127
# appending to it adds new highest-priority revisions
121
128
self.known_revisions = set(rev_history)
131
138
self.pb.update('converting revision', i, len(to_import))
132
139
self._convert_one_rev(rev_id)
134
print 'upgraded to weaves:'
135
print ' %6d revisions and inventories' % len(self.revisions)
136
print ' %6d absent revisions removed' % len(self.absent_revisions)
137
print ' %6d texts' % self.text_count
141
note('upgraded to weaves:')
142
note(' %6d revisions and inventories' % len(self.revisions))
143
note(' %6d absent revisions removed' % len(self.absent_revisions))
144
note(' %6d texts' % self.text_count)
138
145
self._write_all_weaves()
139
146
self._write_all_revs()
149
def _backup_control_dir(self):
150
shutil.copytree('.bzr', '.bzr.backup')
151
note('.bzr has been backed up to .bzr.backup')
152
note('if conversion fails, you can move this directory back to .bzr')
153
note('if it succeeds, you can remove this directory if you wish')
156
def _convert_working_inv(self):
158
inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
159
serializer_v5.write_inventory(inv, branch.controlfile('new-inventory', 'wb'))
142
163
def _write_all_weaves(self):
143
write_a_weave(self.inv_weave, 'weaves/inventory.weave')
144
write_a_weave(self.anc_weave, 'weaves/ancestry.weave')
164
write_a_weave(self.inv_weave, '.bzr/inventory.weave')
165
write_a_weave(self.anc_weave, '.bzr/ancestry.weave')
147
168
for file_id, file_weave in self.text_weaves.items():
148
169
self.pb.update('writing weave', i, len(self.text_weaves))
149
write_a_weave(file_weave, 'weaves/%s.weave' % file_id)
170
write_a_weave(file_weave, '.bzr/weaves/%s.weave' % file_id)