/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/workingtree.py

  • Committer: Robert Collins
  • Date: 2005-11-04 15:05:39 UTC
  • Revision ID: robertc@robertcollins.net-20051104150539-c99884403b7b9e3f
Move revert from Branch to WorkingTree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
506
506
        self.branch._write_inventory(inv)
507
507
 
508
508
    @needs_write_lock
 
509
    def revert(self, filenames, old_tree=None, backups=True):
 
510
        """Restore selected files to the versions from a previous tree.
 
511
 
 
512
        backups
 
513
            If true (default) backups are made of files before
 
514
            they're renamed.
 
515
        """
 
516
        from bzrlib.atomicfile import AtomicFile
 
517
        from bzrlib.osutils import backup_file
 
518
        
 
519
        inv = self.read_working_inventory()
 
520
        if old_tree is None:
 
521
            old_tree = self.branch.basis_tree()
 
522
        old_inv = old_tree.inventory
 
523
 
 
524
        nids = []
 
525
        for fn in filenames:
 
526
            file_id = inv.path2id(fn)
 
527
            if not file_id:
 
528
                raise NotVersionedError(path=fn)
 
529
            if not old_inv.has_id(file_id):
 
530
                raise BzrError("file not present in old tree", fn, file_id)
 
531
            nids.append((fn, file_id))
 
532
            
 
533
        # TODO: Rename back if it was previously at a different location
 
534
 
 
535
        # TODO: If given a directory, restore the entire contents from
 
536
        # the previous version.
 
537
 
 
538
        # TODO: Make a backup to a temporary file.
 
539
 
 
540
        # TODO: If the file previously didn't exist, delete it?
 
541
        for fn, file_id in nids:
 
542
            backup_file(fn)
 
543
            
 
544
            f = AtomicFile(fn, 'wb')
 
545
            try:
 
546
                f.write(old_tree.get_file(file_id).read())
 
547
                f.commit()
 
548
            finally:
 
549
                f.close()
 
550
 
 
551
    @needs_write_lock
509
552
    def set_inventory(self, new_inventory_list):
510
553
        from bzrlib.inventory import (Inventory,
511
554
                                      InventoryDirectory,