[Zope-CVS] SVN: zversioning/trunk/src/versioning/ added some tests recovering some problems concerning reverting to root objects

Grégoire Weber zope.org at incept.ch
Thu Oct 14 10:13:58 EDT 2004


Log message for revision 28185:
  added some tests recovering some problems concerning reverting to root objects

Changed:
  U   zversioning/trunk/src/versioning/README.txt
  U   zversioning/trunk/src/versioning/policies.py
  U   zversioning/trunk/src/versioning/storage.py

-=-
Modified: zversioning/trunk/src/versioning/README.txt
===================================================================
--- zversioning/trunk/src/versioning/README.txt	2004-10-14 13:48:53 UTC (rev 28184)
+++ zversioning/trunk/src/versioning/README.txt	2004-10-14 14:13:57 UTC (rev 28185)
@@ -239,20 +239,11 @@
 
   >>> len(repo.listVersions(sample))
   1
-  >>> repo.checkout(sample)
   >>> sample.text = 'text version 2 of sample'
   >>> repo.checkin(sample)
   >>> sample.text
   'text version 2 of sample'
 
-
-  #>>> repo.revertToVersion(sample, u'001')
-  #>>> db_root['sample'].text
-  'text version 1 of sample'
-  #>>> sample.text
-  'text version 1 of sample'
-
-  
   >>> len(repo.listVersions(sample))
   2
 
@@ -261,3 +252,32 @@
 
   >>> [v.name for v in repo.listVersions(sample)]
   ['Version 1', 'Version 2']
+
+XXX For now the current implementation is not able to revert the root.
+It is possible to handle that but time sliped away at the Isar Sprint.
+
+  >>> repo.revertToVersion(sample, u'001')
+  Traceback (most recent call last):
+  RuntimeError: Can not copy versioned state to root.
+
+So now we work on another objects
+
+  >>> a.text
+  'text version 1 of a'
+  
+  >>> repo.checkout(a)
+  >>> repo.checkin(a)
+  >>> repo.revertToVersion(a, u'001')
+
+XXX Why does thsi raise an exception?
+
+  #>>> repo.checkin(a)
+  #>>> repo.checkout(a)
+  #>>> repo.revertToVersion(a, u'001')
+
+
+Notes
+-----
+
+- During our testing we changed the implementation of the repository
+  and therefore had to throw away the historie storage
\ No newline at end of file

Modified: zversioning/trunk/src/versioning/policies.py
===================================================================
--- zversioning/trunk/src/versioning/policies.py	2004-10-14 13:48:53 UTC (rev 28184)
+++ zversioning/trunk/src/versioning/policies.py	2004-10-14 14:13:57 UTC (rev 28185)
@@ -16,6 +16,7 @@
 from zope.interface import implements
 from zope.app.copypastemove.interfaces import IObjectCopier
 from zope.app.container.interfaces import IContained
+from zope.app.traversing.interfaces import IContainmentRoot
 
 from interfaces import IVersionableAspects
   
@@ -83,9 +84,20 @@
     def copyVersionedData(self, source, target) :
         """ The internal copy routine """
         parent = target.__parent__
-        name = target.__name__       
-        del parent[name]
-        IObjectCopier(source.data).copyTo(parent, name)
+        name = target.__name__
+        
+        # arrggghh!
+        # when the target lives in the zodb root for now we raise an 
+        # exception. We have to think about what reverting to the root
+        # means first.
+        db_root = target._p_jar.root()
+        root_names = db_root.keys()
+        for key, obj in db_root.items():
+            if obj is target:
+                raise RuntimeError, "Can not copy versioned state to root."
+        else:
+            del parent[name]
+            IObjectCopier(source.data).copyTo(parent, name)
 
 
 class ReplaceWithCopyPolicy(VersionableAspectsAdapter) :

Modified: zversioning/trunk/src/versioning/storage.py
===================================================================
--- zversioning/trunk/src/versioning/storage.py	2004-10-14 13:48:53 UTC (rev 28184)
+++ zversioning/trunk/src/versioning/storage.py	2004-10-14 14:13:57 UTC (rev 28185)
@@ -110,7 +110,7 @@
         """
         if obj._p_oid is None :
             raise RuntimeError("cannot version uncommited object")
-        return unicode(obj._p_oid).encode("iso-8859-1")
+        return unicode(obj._p_oid, "iso-8859-1")
         
         # XXX unique id utility is broken
         return str(self.unique_ids.register(obj))



More information about the Zope-CVS mailing list