[Pkg-bazaar-commits] ./bzr/unstable r782: - Branch.revert copies files to backups before reverting them
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:21:01 UTC 2009
------------------------------------------------------------
revno: 782
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Fri 2005-06-24 21:09:36 +1000
message:
- Branch.revert copies files to backups before reverting them
modified:
bzrlib/branch.py
bzrlib/selftest/whitebox.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2005-06-24 10:42:47 +0000
+++ b/bzrlib/branch.py 2005-06-24 11:09:36 +0000
@@ -948,11 +948,16 @@
self.unlock()
- def revert(self, filenames, old_tree=None):
+ def revert(self, filenames, old_tree=None, backups=True):
"""Restore selected files to the versions from a previous tree.
+
+ backups
+ If true (default) backups are made of files before
+ they're renamed.
"""
from bzrlib.errors import NotVersionedError, BzrError
from bzrlib.atomicfile import AtomicFile
+ from bzrlib.osutils import backup_file
inv = self.read_working_inventory()
if old_tree is None:
@@ -964,6 +969,8 @@
file_id = inv.path2id(fn)
if not file_id:
raise NotVersionedError("not a versioned file", fn)
+ if not old_inv.has_id(file_id):
+ raise BzrError("file not present in old tree", fn, file_id)
nids.append((fn, file_id))
# TODO: Rename back if it was previously at a different location
@@ -975,8 +982,8 @@
# TODO: If the file previously didn't exist, delete it?
for fn, file_id in nids:
- if not old_inv.has_id(file_id):
- raise BzrError("file not present in old tree", fn, file_id)
+ backup_file(fn)
+
f = AtomicFile(fn, 'wb')
try:
f.write(old_tree.get_file(file_id).read())
=== modified file 'bzrlib/selftest/whitebox.py'
--- a/bzrlib/selftest/whitebox.py 2005-06-24 11:07:10 +0000
+++ b/bzrlib/selftest/whitebox.py 2005-06-24 11:09:36 +0000
@@ -40,10 +40,12 @@
# revert file modified since last revision
b.revert(['hello.txt'])
self.check_file_contents('hello.txt', 'initial hello')
+ self.check_file_contents('hello.txt~', 'new hello')
- # reverting again causes no change
+ # reverting again clobbers the backup
b.revert(['hello.txt'])
self.check_file_contents('hello.txt', 'initial hello')
+ self.check_file_contents('hello.txt~', 'initial hello')
More information about the Pkg-bazaar-commits
mailing list