Rev 5417: Merge backup-names into orphan-non-versioned-files resolving conflicts in file:///home/vila/src/bzr/bugs/323111-orphans/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Sep 9 14:41:52 BST 2010
At file:///home/vila/src/bzr/bugs/323111-orphans/
------------------------------------------------------------
revno: 5417 [merge]
revision-id: v.ladeuil+lp at free.fr-20100909134152-8ieubk6vfi561zqe
parent: v.ladeuil+lp at free.fr-20100909081439-lrz3d6iob3u8pqz1
parent: v.ladeuil+lp at free.fr-20100909130255-ppyxbb3q137skxbf
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: orphan-non-versioned-files
timestamp: Thu 2010-09-09 15:41:52 +0200
message:
Merge backup-names into orphan-non-versioned-files resolving conflicts
modified:
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/test_bzrdir.py test_bzrdir.py-20060131065654-deba40eef51cf220
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
-------------- next part --------------
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2010-09-09 08:14:39 +0000
+++ b/bzrlib/bzrdir.py 2010-09-09 13:41:52 +0000
@@ -86,6 +86,10 @@
registry,
symbol_versioning,
)
+from bzrlib.symbol_versioning import (
+ deprecated_in,
+ deprecated_method,
+ )
class BzrDir(controldir.ControlDir):
@@ -515,14 +519,13 @@
format=format).bzrdir
return bzrdir.create_workingtree()
+ @deprecated_method(deprecated_in((2, 3, 0)))
def generate_backup_name(self, base):
- """Generate a non-existing backup file name based on base."""
- counter = 1
- name = "%s.~%d~" % (base, counter)
- while self.root_transport.has(name):
- counter += 1
- name = "%s.~%d~" % (base, counter)
- return name
+ return self._available_backup_name(base)
+
+ def _available_backup_name(self, base):
+ """Find a non-existing backup file name based on base."""
+ return osutils.available_backup_name(base, self.root_transport.has)
def backup_bzrdir(self):
"""Backup this bzr control directory.
@@ -530,16 +533,13 @@
:return: Tuple with old path name and new path name
"""
- backup_dir=self.generate_backup_name('backup.bzr')
pb = ui.ui_factory.nested_progress_bar()
try:
- # FIXME: bug 300001 -- the backup fails if the backup directory
- # already exists, but it should instead either remove it or make
- # a new backup directory.
- #
old_path = self.root_transport.abspath('.bzr')
+ backup_dir = self._available_backup_name('backup.bzr')
new_path = self.root_transport.abspath(backup_dir)
- ui.ui_factory.note('making backup of %s\n to %s' % (old_path, new_path,))
+ ui.ui_factory.note('making backup of %s\n to %s'
+ % (old_path, new_path,))
self.root_transport.copy_tree('.bzr', backup_dir)
return (old_path, new_path)
finally:
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2010-09-09 08:14:39 +0000
+++ b/bzrlib/osutils.py 2010-09-09 13:41:52 +0000
@@ -2356,15 +2356,17 @@
return username
-def generate_backup_name(base, exists):
- """Generate a non-existing backup file name.
-
- :param base: The base name.
- :param exists: A callable returning True if the passed path exists.
- """
- counter = 1
+def available_backup_name(base, exists):
+ """Find a non-existing backup file name.
+
+ This will *not* create anything, this only return a 'free' entry.
+
+ :param base: The base name.
+ :param exists: A callable returning True if the passed path exists.
+ """
+ counter = 1
+ name = "%s.~%d~" % (base, counter)
+ while exists(name):
+ counter += 1
name = "%s.~%d~" % (base, counter)
- while exists(name):
- counter += 1
- name = "%s.~%d~" % (base, counter)
- return name
+ return name
=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py 2010-09-09 08:14:39 +0000
+++ b/bzrlib/tests/test_bzrdir.py 2010-09-09 13:41:52 +0000
@@ -32,6 +32,7 @@
repository,
osutils,
remote,
+ symbol_versioning,
urlutils,
win32utils,
workingtree,
@@ -1428,6 +1429,9 @@
class TestGenerateBackupName(TestCaseWithMemoryTransport):
+ # FIXME: This may need to be unified with test_osutils.TestBackupNames or
+ # moved to per_bzrdir or per_transport for better coverage ?
+ # -- vila 20100909
def setUp(self):
super(TestGenerateBackupName, self).setUp()
@@ -1436,9 +1440,14 @@
possible_transports=[self._transport])
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
+ def test_deprecated_generate_backup_name(self):
+ res = self.applyDeprecated(
+ symbol_versioning.deprecated_in((2, 3, 0)),
+ self._bzrdir.generate_backup_name, 'whatever')
+
def test_new(self):
- self.assertEqual("a.~1~", self._bzrdir.generate_backup_name("a"))
+ self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
def test_exiting(self):
self._transport.put_bytes("a.~1~", "some content")
- self.assertEqual("a.~2~", self._bzrdir.generate_backup_name("a"))
+ self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2010-07-08 09:11:44 +0000
+++ b/bzrlib/tests/test_osutils.py 2010-09-09 09:27:33 +0000
@@ -2078,3 +2078,32 @@
ue = osutils.get_user_encoding()
osutils.set_or_unset_env('LOGNAME', u'jrandom\xb6'.encode(ue))
self.assertEqual(u'jrandom\xb6', osutils.getuser_unicode())
+
+class TestBackupNames(tests.TestCase):
+
+ def setUp(self):
+ super(TestBackupNames, self).setUp()
+ self.backups = []
+
+ def backup_exists(self, name):
+ return name in self.backups
+
+ def available_backup_name(self, name):
+ backup_name = osutils.available_backup_name(name, self.backup_exists)
+ self.backups.append(backup_name)
+ return backup_name
+
+ def assertBackupName(self, expected, name):
+ self.assertEqual(expected, self.available_backup_name(name))
+
+ def test_empty(self):
+ self.assertBackupName('file.~1~', 'file')
+
+ def test_existing(self):
+ self.available_backup_name('file')
+ self.available_backup_name('file')
+ self.assertBackupName('file.~3~', 'file')
+ # Empty slots are found, this is not a strict requirement and may be
+ # revisited if we test against all implementations.
+ self.backups.remove('file.~2~')
+ self.assertBackupName('file.~2~', 'file')
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2010-08-20 19:07:17 +0000
+++ b/bzrlib/workingtree.py 2010-09-09 13:02:55 +0000
@@ -2078,9 +2078,10 @@
files_to_backup.append(path[1])
def backup(file_to_backup):
- backup_name = self.bzrdir.generate_backup_name(file_to_backup)
+ backup_name = self.bzrdir._available_backup_name(file_to_backup)
osutils.rename(abs_path, self.abspath(backup_name))
- return "removed %s (but kept a copy: %s)" % (file_to_backup, backup_name)
+ return "removed %s (but kept a copy: %s)" % (file_to_backup,
+ backup_name)
# Build inv_delta and delete files where applicable,
# do this before any modifications to inventory.
More information about the bazaar-commits
mailing list