~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Moved new content generation to pre-renames

Show diffs side-by-side

added added

removed removed

Lines of Context:
482
482
        os.mkdir(self._tree.branch.controlfilename('limbo'))
483
483
        limbo_inv = {}
484
484
        inv = self._tree.inventory
 
485
        self._gen_new_contents()
485
486
        self._apply_removals(inv, limbo_inv)
486
487
        self._apply_insertions(inv, limbo_inv)
487
488
        os.rmdir(self._tree.branch.controlfilename('limbo'))
489
490
        self.__done = True
490
491
        self.finalize()
491
492
 
 
493
    def _limbo_name(self, trans_id):
 
494
        """Generate the limbo name of a file"""
 
495
        limbo = self._tree.branch.controlfilename('limbo')
 
496
        return os.path.join(limbo, trans_id)
 
497
 
 
498
    def _gen_new_contents(self):
 
499
        """\
 
500
        Store new file contents in limbo.
 
501
        This is to avoid problems when the working tree is also one of the
 
502
        input trees.
 
503
        """
 
504
        for trans_id, content in self._new_contents.iteritems():
 
505
            kind = content[0]
 
506
            path = self._limbo_name(trans_id)
 
507
            if kind == 'file':
 
508
                f = file(path, 'wb')
 
509
                for segment in content[1]:
 
510
                    f.write(segment)
 
511
                f.close()
 
512
            elif kind == 'directory':
 
513
                os.mkdir(self._tree.abspath(path))
 
514
            elif kind == 'symlink':
 
515
                target = self._new_contents[trans_id][1]
 
516
                os.symlink(target, self._tree.abspath(path))
 
517
        
 
518
 
492
519
    def _apply_removals(self, inv, limbo_inv):
493
520
        """Perform tree operations that remove directory/inventory names.
494
521
        
540
567
                kind = self._new_contents[trans_id][0]
541
568
            except KeyError:
542
569
                kind = contents = None
543
 
            if kind == 'file':
544
 
                contents = self._new_contents[trans_id][1]
545
 
                f = file(self._tree.abspath(path), 'wb')
546
 
                for segment in contents:
547
 
                    f.write(segment)
548
 
                f.close()
549
 
            elif kind == 'directory':
550
 
                os.mkdir(self._tree.abspath(path))
551
 
            elif kind == 'symlink':
552
 
                target = self._new_contents[trans_id][1]
553
 
                os.symlink(target, self._tree.abspath(path))
554
 
            elif kind is None and (trans_id in self._new_name or
555
 
                                   trans_id in self._new_parent):
 
570
            if trans_id in self._new_contents or self.path_changed(trans_id):
556
571
                full_path = self._tree.abspath(path)
557
572
                try:
558
 
                    os.rename(os.path.join(limbo, trans_id), full_path)
 
573
                    os.rename(self._limbo_name(trans_id), full_path)
559
574
                except OSError, e:
560
575
                    # We may be renaming a dangling inventory id
561
576
                    if e.errno != errno.ENOENT: