~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/dirstate.py

Move fast id => path lookups down into DirState
It belongs there anyway, and it means all _get_entry(file_id) lookups
will be improved, rather than just id2path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
360
360
           # insert a new dirblock
361
361
           self._ensure_block(block_index, entry_index, utf8path)
362
362
        self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
363
        if self._id_index:
 
364
            self._id_index.setdefault(entry_key[2], set()).add(entry_key)
363
365
 
364
366
    def _bisect(self, dir_name_list):
365
367
        """Bisect through the disk structure for specific rows.
1167
1169
                                          ' tree_index, file_id and path')
1168
1170
            return entry
1169
1171
        else:
1170
 
            for entry in self._iter_entries():
1171
 
                if entry[0][2] == fileid_utf8:
1172
 
                    if entry[1][tree_index][0] == 'r': # relocated
1173
 
                        # look up the real location directly by path
1174
 
                        return self._get_entry(tree_index,
1175
 
                            fileid_utf8=fileid_utf8,
1176
 
                            path_utf8=entry[1][tree_index][1])
1177
 
                    if entry[1][tree_index][0] == 'a': # absent
1178
 
                        # not in the tree at all.
1179
 
                        return None, None
 
1172
            possible_keys = self._get_id_index().get(fileid_utf8, None)
 
1173
            if not possible_keys:
 
1174
                return None, None
 
1175
            for key in possible_keys:
 
1176
                (block_index, entry_index, dir_present,
 
1177
                 file_present) = self._get_block_entry_index(key[0], key[1],
 
1178
                                                             tree_index)
 
1179
                if file_present:
 
1180
                    entry = self._dirblocks[block_index][1][entry_index]
 
1181
                    assert entry[1][tree_index][0] not in ('a', 'r')
 
1182
                    assert key == entry[0]
1180
1183
                    return entry
1181
1184
            return None, None
1182
1185
 
1490
1493
        self._header_state = DirState.IN_MEMORY_MODIFIED
1491
1494
        self._dirblock_state = DirState.IN_MEMORY_MODIFIED
1492
1495
        self._parents = list(parent_ids)
 
1496
        self._id_index = None
1493
1497
 
1494
1498
    def set_path_id(self, path, new_id):
1495
1499
        """Change the id of path to new_id in the current working tree.
1513
1517
        self.update_minimal(('', '', new_id), 'd',
1514
1518
            path_utf8='', packed_stat=entry[1][0][4])
1515
1519
        self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
1520
        if self._id_index is not None:
 
1521
            self._id_index.setdefault(new_id, set()).add(entry[0])
1516
1522
 
1517
1523
    def set_parent_trees(self, trees, ghosts):
1518
1524
        """Set the parent trees for the dirstate.
1733
1739
                self._make_absent(current_old)
1734
1740
                current_old = advance(old_iterator)
1735
1741
        self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
1742
        self._id_index = None
1736
1743
 
1737
1744
    def _make_absent(self, current_old):
1738
1745
        """Mark current_old - an entry - as absent for tree 0.