2171
2171
InterTree.register_optimiser(InterDirStateTree)
2174
class Converter3to4(object):
2175
"""Perform an in-place upgrade of format 3 to format 4 trees."""
2178
self.target_format = WorkingTreeFormat4()
2180
def convert(self, tree):
2181
# lock the control files not the tree, so that we dont get tree
2182
# on-unlock behaviours, and so that noone else diddles with the
2183
# tree during upgrade.
2184
tree._control_files.lock_write()
2186
self.create_dirstate_data(tree)
2187
self.update_format(tree)
2188
self.remove_xml_files(tree)
2190
tree._control_files.unlock()
2192
def create_dirstate_data(self, tree):
2193
"""Create the dirstate based data for tree."""
2194
local_path = tree.bzrdir.get_workingtree_transport(None
2195
).local_abspath('dirstate')
2196
state = dirstate.DirState.from_tree(tree, local_path)
2200
def remove_xml_files(self, tree):
2201
"""Remove the oldformat 3 data."""
2202
transport = tree.bzrdir.get_workingtree_transport(None)
2203
for path in ['basis-inventory-cache', 'inventory', 'last-revision',
2204
'pending-merges', 'stat-cache']:
2205
transport.delete(path)
2207
def update_format(self, tree):
2208
"""Change the format marker."""
2209
tree._control_files.put_utf8('format',
2210
self.target_format.get_format_string())