506
506
self.branch._write_inventory(inv)
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.
513
If true (default) backups are made of files before
516
from bzrlib.atomicfile import AtomicFile
517
from bzrlib.osutils import backup_file
519
inv = self.read_working_inventory()
521
old_tree = self.branch.basis_tree()
522
old_inv = old_tree.inventory
526
file_id = inv.path2id(fn)
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))
533
# TODO: Rename back if it was previously at a different location
535
# TODO: If given a directory, restore the entire contents from
536
# the previous version.
538
# TODO: Make a backup to a temporary file.
540
# TODO: If the file previously didn't exist, delete it?
541
for fn, file_id in nids:
544
f = AtomicFile(fn, 'wb')
546
f.write(old_tree.get_file(file_id).read())
509
552
def set_inventory(self, new_inventory_list):
510
553
from bzrlib.inventory import (Inventory,
511
554
InventoryDirectory,