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.
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()
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
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())
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([])
551
520
@needs_write_lock
552
521
def set_inventory(self, new_inventory_list):