/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Got file renaming working

Show diffs side-by-side

added added

removed removed

Lines of Context:
353
353
        """
354
354
        if len(self.find_conflicts()) != 0:
355
355
            raise MalformedTransform()
 
356
        os.mkdir(self._tree.branch.controlfilename('limbo'))
356
357
        inv = self._tree.inventory
357
 
        for trans_id in self._removed_contents:
 
358
        self._apply_removals(inv)
 
359
        self._apply_insertions(inv)
 
360
 
 
361
        os.rmdir(self._tree.branch.controlfilename('limbo'))
 
362
        self._tree._write_inventory(inv)
 
363
        self.__done = True
 
364
 
 
365
    def _apply_removals(self, inv):
 
366
        limbo = self._tree.branch.controlfilename('limbo')
 
367
        tree_paths = list(self._tree_path_ids.iteritems())
 
368
        tree_paths.sort(reverse=True)
 
369
        for path, trans_id in tree_paths:
358
370
            if trans_id in self._removed_contents:
359
 
                path = self._tree_id_paths[trans_id]
360
371
                try:
361
372
                    os.unlink(path)
362
373
                except OSError, e:
363
374
                    if e.errno != errno.EISDIR:
364
375
                        raise
365
376
                    os.rmdir(path)
 
377
            elif trans_id in self._new_name or trans_id in self._new_parent:
 
378
                os.rename(path, os.path.join(limbo, trans_id))
366
379
 
 
380
    def _apply_insertions(self, inv):
 
381
        limbo = self._tree.branch.controlfilename('limbo')
367
382
        for path, trans_id in self.new_paths():
368
383
            try:
369
384
                kind = self._new_contents[trans_id][0]
380
395
            elif kind == 'symlink':
381
396
                target = self._new_contents[trans_id][1]
382
397
                os.symlink(target, path)
 
398
            elif kind is None and (trans_id in self._new_name or
 
399
                                   trans_id in self._new_parent):
 
400
                os.rename(os.path.join(limbo, trans_id), path)
 
401
 
383
402
 
384
403
            if trans_id in self._new_id:
385
404
                if kind is None:
388
407
            # requires files and inventory entries to be in place
389
408
            if trans_id in self._new_executability:
390
409
                self._set_executability(path, inv, trans_id)
391
 
 
392
 
        self._tree._write_inventory(inv)
393
 
        self.__done = True
394
 
 
395
410
    def _set_executability(self, path, inv, trans_id):
396
411
        file_id = inv.path2id(path)
397
412
        new_executability = self._new_executability[trans_id]