~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

Implement upgrade for working trees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2169
2169
        return True
2170
2170
 
2171
2171
InterTree.register_optimiser(InterDirStateTree)
 
2172
 
 
2173
 
 
2174
class Converter3to4(object):
 
2175
    """Perform an in-place upgrade of format 3 to format 4 trees."""
 
2176
 
 
2177
    def __init__(self):
 
2178
        self.target_format = WorkingTreeFormat4()
 
2179
 
 
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()
 
2185
        try:
 
2186
            self.create_dirstate_data(tree)
 
2187
            self.update_format(tree)
 
2188
            self.remove_xml_files(tree)
 
2189
        finally:
 
2190
            tree._control_files.unlock()
 
2191
 
 
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)
 
2197
        state.save()
 
2198
        state.unlock()
 
2199
 
 
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)
 
2206
 
 
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())