~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-02-28 03:22:58 UTC
  • mfrom: (3146.8.20 no-inventory5)
  • Revision ID: pqm@pqm.ubuntu.com-20080228032258-4mdmqlx603ak6x2w
Implement checkout entirely via dirstate (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1166
1166
            raise
1167
1167
        return result
1168
1168
 
 
1169
    def update_by_delta(self, delta):
 
1170
        """Apply an inventory delta to the dirstate for tree 0
 
1171
 
 
1172
        :param delta: An inventory delta.  See Inventory.apply_delta for
 
1173
            details.
 
1174
        """
 
1175
        self._read_dirblocks_if_needed()
 
1176
        insertions = {}
 
1177
        removals = {}
 
1178
        for old_path, new_path, file_id, inv_entry in sorted(delta,
 
1179
                                                             reverse=True):
 
1180
            assert file_id not in insertions
 
1181
            assert file_id not in removals
 
1182
            if old_path is not None:
 
1183
                old_path = old_path.encode('utf-8')
 
1184
                removals[file_id] = old_path
 
1185
            if new_path is not None:
 
1186
                new_path = new_path.encode('utf-8')
 
1187
                dirname, basename = osutils.split(new_path)
 
1188
                key = (dirname, basename, file_id)
 
1189
                minikind = DirState._kind_to_minikind[inv_entry.kind]
 
1190
                if minikind == 't':
 
1191
                    fingerprint = inv_entry.reference_revision
 
1192
                else:
 
1193
                    fingerprint = ''
 
1194
                insertions[file_id] = (key, minikind, inv_entry.executable,
 
1195
                                       fingerprint, new_path)
 
1196
            if None not in (old_path, new_path):
 
1197
                for child in self._iter_child_entries(0, old_path):
 
1198
                    if child[0][2] in insertions or child[0][2] in removals:
 
1199
                        continue
 
1200
                    child_dirname = child[0][0]
 
1201
                    child_basename = child[0][1]
 
1202
                    minikind = child[1][0][0]
 
1203
                    fingerprint = child[1][0][4]
 
1204
                    executable = child[1][0][3]
 
1205
                    old_child_path = osutils.pathjoin(child[0][0],
 
1206
                                                      child[0][1])
 
1207
                    removals[child[0][2]] = old_child_path
 
1208
                    child_suffix = child_dirname[len(old_path):]
 
1209
                    new_child_dirname = (new_path + child_suffix)
 
1210
                    key = (new_child_dirname, child_basename, child[0][2])
 
1211
                    new_child_path = os.path.join(new_child_dirname,
 
1212
                                                  child_basename)
 
1213
                    insertions[child[0][2]] = (key, minikind, executable,
 
1214
                                               fingerprint, new_child_path)
 
1215
        self._apply_removals(removals.values())
 
1216
        self._apply_insertions(insertions.values())
 
1217
 
 
1218
    def _apply_removals(self, removals):
 
1219
        for path in sorted(removals, reverse=True):
 
1220
            dirname, basename = osutils.split(path)
 
1221
            block_i, entry_i, d_present, f_present = \
 
1222
                self._get_block_entry_index(dirname, basename, 0)
 
1223
            entry = self._dirblocks[block_i][1][entry_i]
 
1224
            self._make_absent(entry)
 
1225
 
 
1226
    def _apply_insertions(self, adds):
 
1227
        for key, minikind, executable, fingerprint, path_utf8 in sorted(adds):
 
1228
            self.update_minimal(key, minikind, executable, fingerprint,
 
1229
                                path_utf8=path_utf8)
 
1230
 
1169
1231
    def update_basis_by_delta(self, delta, new_revid):
1170
1232
        """Update the parents of this tree after a commit.
1171
1233