[Zope-CVS] CVS: Products/ZopeVersionControl - CHANGES.txt:1.1 Repository.py:1.7 version.txt:1.2

Shane Hathaway cvs-admin at zope.org
Mon Oct 27 15:19:15 EST 2003


Update of /cvs-repository/Products/ZopeVersionControl
In directory cvs.zope.org:/tmp/cvs-serv11590

Modified Files:
	Repository.py version.txt 
Added Files:
	CHANGES.txt 
Log Message:
ZopeVersionControl now works harder at retaining object identity.

Now, updateResource() and uncheckoutResource() never replace an
object with a new object, but instead change the state of an
existing object.


=== Added File Products/ZopeVersionControl/CHANGES.txt ===
Version 0.3

  - updateResource() and uncheckoutResource() now retain the identity
    of the object being versioned.  That is, they never replace an
    object with a new object, but instead change the state of an
    existing object.

    updateResource() and uncheckoutResource() used to replace the
    object in its container, but this strategy had two flaws:

      1. It required ZopeVersionControl to use the ObjectManager API.
      Version control should not require versionable objects to be
      contained in ObjectManagers.

      2. It assumes that versionable objects are simply wrapped using
      acquisition.  References (symlink-like objects) break this
      assumption.



=== Products/ZopeVersionControl/Repository.py 1.6 => 1.7 ===
--- Products/ZopeVersionControl/Repository.py:1.6	Tue May 13 18:12:31 2003
+++ Products/ZopeVersionControl/Repository.py	Mon Oct 27 15:19:15 2003
@@ -62,18 +62,29 @@
         """Internal: return a version history given a version history id."""
         return self._histories[history_id].__of__(self)
 
-    security.declarePrivate('replaceObject')
-    def replaceObject(self, obj, new_obj):
-        """Internal: replace a persistent object in its container."""
+    security.declarePrivate('replaceState')
+    def replaceState(self, obj, new_state):
+        """Internal: replace the state of a persistent object.
+        """
         subitems = getVCItems(obj)
-        container = aq_parent(aq_inner(obj))
-        item_id = obj.getId()
-        container._delOb(item_id)
-        container._setOb(item_id, new_obj)
-        res = container._getOb(item_id)
+        # XXX There ought to be some way to do this more cleanly.
+        # This fills the __dict__ of the old object with new state.
+        # This replace the object in its container, but applications
+        # that use version control turned out much simpler when the
+        # identity of the object was retained.
+        if obj.__class__ is not new_state.__class__:
+            raise VersionControlError(
+                "The class of the versioned object has changed. %s != %s"
+                % (repr(obj.__class__, new_state.__class__)))
+        obj._p_changed = 1
+        for key in obj.__dict__.keys():
+            if not new_state.__dict__.has_key(key):
+                del obj.__dict__[key]
+        for key, value in new_state.__dict__.items():
+            obj.__dict__[key] = value
         if subitems:
-            restoreVCItems(res, subitems)
-        return res
+            restoreVCItems(obj, subitems)
+        return obj
 
     #####################################################################
     # This is the implementation of the public version control interface.
@@ -268,8 +279,8 @@
                             ob_path
                             )
 
-        # Re-seat the reverted object in its container.
-        new_obj = self.replaceObject(object, new_obj)
+        # Replace the state of the object with a reverted state.
+        new_obj = self.replaceState(object, new_obj)
 
         # Update bookkeeping information.
         newinfo = info.clone()
@@ -345,7 +356,7 @@
         new_object = object
         if version and (version_id != info.version_id):
             new_object = version.copyState()
-            new_object = self.replaceObject(object, new_object)
+            new_object = self.replaceState(object, new_object)
 
             history.addLogEntry(version_id,
                                 LogEntry.ACTION_UPDATE,


=== Products/ZopeVersionControl/version.txt 1.1 => 1.2 ===
--- Products/ZopeVersionControl/version.txt:1.1	Tue May 27 16:05:50 2003
+++ Products/ZopeVersionControl/version.txt	Mon Oct 27 15:19:15 2003
@@ -1 +1 @@
-0.2
+ZopeVersionControl-0.2+




More information about the Zope-CVS mailing list