From 44b4e3f8b6405d0e1e0ebf6cb526ab62cdbbdb25 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 8 Dec 2009 08:54:50 -0500 Subject: Transitioned bugdir.py to new storage format. --- libbe/storage/base.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'libbe/storage/base.py') diff --git a/libbe/storage/base.py b/libbe/storage/base.py index 3526462..eb2b94c 100644 --- a/libbe/storage/base.py +++ b/libbe/storage/base.py @@ -33,11 +33,11 @@ class InvalidRevision (KeyError): class NotWriteable (NotSupported): def __init__(self, msg): - NotSupported.__init__('write', msg) + NotSupported.__init__(self, 'write', msg) class NotReadable (NotSupported): def __init__(self, msg): - NotSupported.__init__('read', msg) + NotSupported.__init__(self, 'read', msg) class EmptyCommit(Exception): def __init__(self): @@ -182,7 +182,11 @@ class Storage (object): """Add an entry""" if self.is_writeable() == False: raise NotWriteable('Cannot add entry to unwriteable storage.') - self._add(*args, **kwargs) + try: # Maybe we've already added that id? + self.get(id) + pass # yup, no need to add another + except InvalidID: + self._add(*args, **kwargs) def _add(self, id, parent=None): if parent == None: @@ -436,6 +440,15 @@ if TESTING == True: """New repository should be empty.""" self.failUnless(len(self.s.children()) == 0, self.s.children()) + def test_add_rooted(self): + """ + Adding entries with the same ID should not increase the number of children. + """ + for i in range(10): + self.s.add('some id') + s = sorted(self.s.children()) + self.failUnless(s == ['some id'], s) + def test_add_rooted(self): """ Adding entries should increase the number of children (rooted). -- cgit