~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: James Westby
  • Date: 2008-08-01 16:10:59 UTC
  • mto: This revision was merged to the branch mainline in revision 3609.
  • Revision ID: jw+debian@jameswestby.net-20080801161059-xbtyoclmjhaf13qz
Add a test for creating hardlinks as well.

Also, don't keep state, but calculate all of the kind changes
at apply time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
        self._case_sensitive_target = case_sensitive
138
138
        # A counter of how many files have been renamed
139
139
        self.rename_count = 0
140
 
        # A set of the trans_ids that have changed kind
141
 
        self._kind_change = set()
142
140
 
143
141
    def __get_root(self):
144
142
        return self._new_root
324
322
        New file takes the permissions of any existing file with that id,
325
323
        unless mode_id is specified.
326
324
        """
327
 
        if not self._does_tree_kind_match(trans_id, 'file'):
328
 
            self._kind_change.add(trans_id)
329
325
        name = self._limbo_name(trans_id)
330
326
        f = open(name, 'wb')
331
327
        try:
386
382
            os.unlink(name)
387
383
            raise
388
384
 
389
 
    def _does_tree_kind_match(self, trans_id, kind):
390
 
        """Checks whether the kind of trans_id has changed from the tree.
391
 
 
392
 
        Returns True if trans_id exists in the tree and matches the
393
 
        kind passed. Returns False otherwise.
394
 
        """
395
 
        try:
396
 
            if self.tree_kind(trans_id) == kind:
397
 
                return True
398
 
        except NoSuchFile:
399
 
            pass
400
 
        return False
401
 
 
402
385
    def create_directory(self, trans_id):
403
386
        """Schedule creation of a new directory.
404
387
        
405
388
        See also new_directory.
406
389
        """
407
 
        if not self._does_tree_kind_match(trans_id, 'directory'):
408
 
            self._kind_change.add(trans_id)
409
390
        os.mkdir(self._limbo_name(trans_id))
410
391
        unique_add(self._new_contents, trans_id, 'directory')
411
392
 
415
396
        target is a bytestring.
416
397
        See also new_symlink.
417
398
        """
418
 
        if not self._does_tree_kind_match(trans_id, 'symlink'):
419
 
            self._kind_change.add(trans_id)
420
399
        if has_symlinks():
421
400
            os.symlink(target, self._limbo_name(trans_id))
422
401
            unique_add(self._new_contents, trans_id, 'symlink')
1238
1217
                mover = _mover
1239
1218
            try:
1240
1219
                child_pb.update('Apply phase', 0, 2)
1241
 
                self._apply_removals(new_inventory_delta, mover)
 
1220
                kind_changes = self._apply_removals(new_inventory_delta, mover)
1242
1221
                child_pb.update('Apply phase', 1, 2)
1243
1222
                modified_paths = self._apply_insertions(new_inventory_delta,
1244
 
                                                        mover)
 
1223
                                                        mover, kind_changes)
1245
1224
            except:
1246
1225
                mover.rollback()
1247
1226
                raise
1265
1244
        """
1266
1245
        tree_paths = list(self._tree_path_ids.iteritems())
1267
1246
        tree_paths.sort(reverse=True)
 
1247
        kind_changes = set()
1268
1248
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1269
1249
        try:
1270
1250
            for num, data in enumerate(tree_paths):
1272
1252
                child_pb.update('removing file', num, len(tree_paths))
1273
1253
                full_path = self._tree.abspath(path)
1274
1254
                if trans_id in self._removed_contents:
 
1255
                    try:
 
1256
                        if (self.tree_kind(trans_id)
 
1257
                                != self.final_kind(trans_id)):
 
1258
                            kind_changes.add(trans_id)
 
1259
                    except NoSuchFile:
 
1260
                        pass
1275
1261
                    mover.pre_delete(full_path, os.path.join(self._deletiondir,
1276
1262
                                     trans_id))
1277
1263
                elif trans_id in self._new_name or trans_id in \
1295
1281
                    inventory_delta.append((path, None, file_id, None))
1296
1282
        finally:
1297
1283
            child_pb.finished()
 
1284
        return kind_changes
1298
1285
 
1299
 
    def _apply_insertions(self, inventory_delta, mover):
 
1286
    def _apply_insertions(self, inventory_delta, mover, kind_changes):
1300
1287
        """Perform tree operations that insert directory/inventory names.
1301
1288
 
1302
1289
        That is, create any files that need to be created, and restore from
1305
1292
 
1306
1293
        If inventory_delta is None, no inventory delta is calculated, and
1307
1294
        no list of modified paths is returned.
 
1295
 
 
1296
        kind_changes is a set of trans ids where the entry has changed
 
1297
        kind, and so an inventory delta entry should be created for them.
1308
1298
        """
1309
1299
        new_paths = self.new_paths(filesystem_only=(inventory_delta is None))
1310
1300
        modified_paths = []
1342
1332
                        trans_id in self._new_name or
1343
1333
                        trans_id in self._new_parent
1344
1334
                        or trans_id in self._new_executability
1345
 
                        or trans_id in self._kind_change):
 
1335
                        or trans_id in kind_changes):
1346
1336
                        try:
1347
1337
                            kind = self.final_kind(trans_id)
1348
1338
                        except NoSuchFile: