~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2005-11-05 14:48:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1503.
  • Revision ID: robertc@robertcollins.net-20051105144839-0778253797be08ec
Replace the WorkingTree.revert method algorithm with a call to merge_inner.

Show diffs side-by-side

added added

removed removed

Lines of Context:
507
507
 
508
508
    @needs_write_lock
509
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()
 
510
        from bzrlib.merge import merge_inner
520
511
        if old_tree is None:
521
512
            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()
 
513
        merge_inner(self.branch, old_tree,
 
514
                    self, ignore_zero=True,
 
515
                    backup_files=backups, 
 
516
                    interesting_files=filenames)
 
517
        if not len(filenames):
 
518
            self.branch.set_pending_merges([])
550
519
 
551
520
    @needs_write_lock
552
521
    def set_inventory(self, new_inventory_list):