Rev 2673: Prevent the duplicate additions of names to FileNames collections. in http://people.ubuntu.com/~robertc/baz2.0/names-collection-user-specified
Robert Collins
robertc at robertcollins.net
Tue Aug 7 00:49:22 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/names-collection-user-specified
------------------------------------------------------------
revno: 2673
revision-id: robertc at robertcollins.net-20070806234918-xc9w5f86tgjphf9u
parent: robertc at robertcollins.net-20070806054732-0w8j16bf4upvt2nu
committer: Robert Collins <robertc at robertcollins.net>
branch nick: names-collection-user-specified
timestamp: Tue 2007-08-07 09:49:18 +1000
message:
Prevent the duplicate additions of names to FileNames collections.
modified:
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/file_names.py file_collection.py-20070714100753-j2zz4ahtk331k5zm-1
bzrlib/tests/test_file_names.py test_file_collection-20070714093417-5gc9d821to85zo4t-1
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-07-20 18:59:29 +0000
+++ b/bzrlib/errors.py 2007-08-06 23:49:18 +0000
@@ -1625,6 +1625,7 @@
self.text_revision = text_revision
self.file_id = file_id
+
class DuplicateFileId(BzrError):
_fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
=== modified file 'bzrlib/file_names.py'
--- a/bzrlib/file_names.py 2007-08-06 05:47:32 +0000
+++ b/bzrlib/file_names.py 2007-08-06 23:49:18 +0000
@@ -58,10 +58,13 @@
"""Allocate name in the names collection.
:param name: The name to allocate.
+ :raises: bzrlib.errors.DuplicateKey if the name is already allocated.
"""
if name is not None:
if len(self._names) >= self._cap:
raise errors.BzrError('too many files')
+ if name in self._names:
+ raise errors.DuplicateKey(name)
self._names.add(name)
return name
=== modified file 'bzrlib/tests/test_file_names.py'
--- a/bzrlib/tests/test_file_names.py 2007-08-06 05:47:32 +0000
+++ b/bzrlib/tests/test_file_names.py 2007-08-06 23:49:18 +0000
@@ -33,6 +33,13 @@
names.save()
self.assertEqual('', t.get_bytes(name))
+ def test_allocate_duplicate_name_errors(self):
+ t = self.get_transport()
+ names = FileNames(t, 'index')
+ names.initialise()
+ names.allocate('0')
+ self.assertRaises(errors.DuplicateKey, names.allocate, '0')
+
def test_allocate_name_does_not_error(self):
t = self.get_transport()
names = FileNames(t, 'index')
More information about the bazaar-commits
mailing list