[Checkins] SVN: z3c.vcsync/trunk/src/z3c/vcsync/ Also found support for containers.

Martijn Faassen faassen at infrae.com
Mon Apr 28 11:20:07 EDT 2008


Log message for revision 85818:
  Also found support for containers.
  

Changed:
  U   z3c.vcsync/trunk/src/z3c/vcsync/README.txt
  U   z3c.vcsync/trunk/src/z3c/vcsync/svn.py

-=-
Modified: z3c.vcsync/trunk/src/z3c/vcsync/README.txt
===================================================================
--- z3c.vcsync/trunk/src/z3c/vcsync/README.txt	2008-04-28 15:18:59 UTC (rev 85817)
+++ z3c.vcsync/trunk/src/z3c/vcsync/README.txt	2008-04-28 15:20:06 UTC (rev 85818)
@@ -89,6 +89,7 @@
   ...     implements(IState)
   ...     def __init__(self, root):
   ...         self.root = root
+  ...         self._removed = []
   ...     def set_revision_nr(self, nr):
   ...         self.root.nr = nr
   ...     def get_revision_nr(self):
@@ -97,7 +98,7 @@
   ...         except AttributeError:
   ...             return 0
   ...     def removed(self, revision_nr):
-  ...         return []
+  ...         return self._removed
   ...     def objects(self, revision_nr):
   ...         for container in self._containers(revision_nr):
   ...             for value in container.values():
@@ -457,3 +458,58 @@
   >>> info = found_s.sync("Synchronize")
   >>> found_data['root']['sub']['qux'].payload
   36
+
+Folder conflicts
+----------------
+
+Let's now examine a case of a conflict in case of containers.
+
+A user (we'll call him ``user1``) creates a new container in ``data``
+with some content in it, and synchronize it::
+
+  >>> current_synchronizer = s
+  >>> data['folder'] = Container()
+  >>> data['folder']['content'] = Item(14)
+  >>> info = s.sync("Synchronize")
+
+We'll synchronize this into ``data2`` so that the second user (``user2``) has
+access to it::
+
+  >>> current_synchronizer = s2
+  >>> info = s2.sync("Synchronize")
+
+``user1`` now throws away ``folder`` in ``data`` and synchronizes this,
+causing ``folder`` to be gone in SVN::
+
+  >>> current_synchronizer = s
+  >>> from z3c.vcsync.vc import get_object_path
+  >>> state._removed.append(get_object_path(data, data['folder']))
+  >>> del data['folder']
+  >>> info = s.sync("Synchronize")
+
+Meanwhile, ``user2`` happily alters data in ``folder`` by changing
+``content`` in instance 2::
+
+  >>> current_synchronizer = s2
+  >>> data2['folder']['content'].payload = 15
+
+Now ``user2`` does a synchronization too::
+
+  >>> info = s2.sync("Synchronize")
+
+All changes ``user2`` made are now gone, as ``folder`` is gone::
+
+  >>> 'folder' in data2
+  False
+
+The folder with its content can however be retrieved in the found data
+section::
+
+  >>> found_s = Synchronizer(checkout, found_state)
+  >>> current_synchronizer = found_s
+  >>> info = found_s.sync("synchronize")
+  >>> found_data['root']['folder']['content'].payload
+  15
+
+
+

Modified: z3c.vcsync/trunk/src/z3c/vcsync/svn.py
===================================================================
--- z3c.vcsync/trunk/src/z3c/vcsync/svn.py	2008-04-28 15:18:59 UTC (rev 85817)
+++ z3c.vcsync/trunk/src/z3c/vcsync/svn.py	2008-04-28 15:20:06 UTC (rev 85818)
@@ -71,6 +71,20 @@
         save_path.ensure()
         save_path.write(content)
 
+    def _found_container(self, path):
+        """Store conflicting/lost container in found directory.
+
+        path - the path in the original tree. This is translated to
+               a found path with the same structure.
+        """
+        found = self.path.ensure('found', dir=True)
+        rel_path = path.relto(self.path)
+        save_path = found.join(*rel_path.split(path.sep))
+        py.path.local(path.strpath).copy(save_path)
+        save_path.add()
+        for new_path in save_path.visit():
+            new_path.add()
+            
     def _update_files(self, revision_nr):
         """Go through svn log and update self._files and self._removed.
         """
@@ -120,11 +134,17 @@
             if not p.check(dir=True):
                 continue
             try:
+                # resolve any direct conflicts
                 for conflict in p.status().conflict:
                     mine, other = conflict_info(conflict)
                     conflict.write(mine.read())
                     self._found(conflict, other.read())
                     conflict._svn('resolved')
+                # move any status unknown directories away
+                for unknown in p.status().unknown:
+                    if unknown.check(dir=True):
+                        self._found_container(unknown)
+                        unknown.remove()
             # XXX This is a horrible hack to skip status of R. This
             # is not supported by Py 0.9.0, and raises a NotImplementedError.
             # This has been fixed on the trunk of Py.



More information about the Checkins mailing list