~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
335
335
                elif kind == 'directory':
336
336
                    # add this entry to the parent map.
337
337
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
 
338
                elif kind == 'tree-reference':
 
339
                    inv_entry.reference_revision = link_or_sha1
 
340
                else:
 
341
                    assert 'unknown kind'
338
342
                # These checks cost us around 40ms on a 55k entry tree
339
343
                assert file_id not in inv_byid, ('file_id %s already in'
340
344
                    ' inventory as %s' % (file_id, inv_byid[file_id]))
1204
1208
    def __get_matchingbzrdir(self):
1205
1209
        # please test against something that will let us do tree references
1206
1210
        return bzrdir.format_registry.make_bzrdir(
1207
 
            'experimental-reference-dirstate')
 
1211
            'dirstate-with-subtree')
1208
1212
 
1209
1213
    _matchingbzrdir = property(__get_matchingbzrdir)
1210
1214
 
2179
2183
        return True
2180
2184
 
2181
2185
InterTree.register_optimiser(InterDirStateTree)
 
2186
 
 
2187
 
 
2188
class Converter3to4(object):
 
2189
    """Perform an in-place upgrade of format 3 to format 4 trees."""
 
2190
 
 
2191
    def __init__(self):
 
2192
        self.target_format = WorkingTreeFormat4()
 
2193
 
 
2194
    def convert(self, tree):
 
2195
        # lock the control files not the tree, so that we dont get tree
 
2196
        # on-unlock behaviours, and so that noone else diddles with the 
 
2197
        # tree during upgrade.
 
2198
        tree._control_files.lock_write()
 
2199
        try:
 
2200
            self.create_dirstate_data(tree)
 
2201
            self.update_format(tree)
 
2202
            self.remove_xml_files(tree)
 
2203
        finally:
 
2204
            tree._control_files.unlock()
 
2205
 
 
2206
    def create_dirstate_data(self, tree):
 
2207
        """Create the dirstate based data for tree."""
 
2208
        local_path = tree.bzrdir.get_workingtree_transport(None
 
2209
            ).local_abspath('dirstate')
 
2210
        state = dirstate.DirState.from_tree(tree, local_path)
 
2211
        state.save()
 
2212
        state.unlock()
 
2213
 
 
2214
    def remove_xml_files(self, tree):
 
2215
        """Remove the oldformat 3 data."""
 
2216
        transport = tree.bzrdir.get_workingtree_transport(None)
 
2217
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
 
2218
            'pending-merges', 'stat-cache']:
 
2219
            try:
 
2220
                transport.delete(path)
 
2221
            except errors.NoSuchFile:
 
2222
                # some files are optional - just deal.
 
2223
                pass
 
2224
 
 
2225
    def update_format(self, tree):
 
2226
        """Change the format marker."""
 
2227
        tree._control_files.put_utf8('format',
 
2228
            self.target_format.get_format_string())