← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug-1111487 into lp:zorba

 

Ghislain Fourny has proposed merging lp:~zorba-coders/zorba/bug-1111487 into lp:zorba.

Commit message:
Fixing bug 1111487 (db:edit swaps).

Requested reviews:
  Dennis Knochenwefel (dennis-knochenwefel)
  Till Westmann (tillw)
Related bugs:
  Bug #1111487 in Zorba: "When editing a node in a collection, the collection information does not get swapped."
  https://bugs.launchpad.net/zorba/+bug/1111487

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1111487/+merge/145868

Fixing bug 1111487 (db:edit swaps).
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1111487/+merge/145868
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp	2013-01-11 00:45:15 +0000
+++ src/store/naive/node_items.cpp	2013-01-31 14:16:24 +0000
@@ -767,20 +767,13 @@
   assert(theParent == NULL);
   assert(lOtherItem->theParent == NULL);
 
-  // Swap flags expect hasReference.
-  bool lHasReference = haveReference();
-  bool lOtherHasReference = lOtherItem->haveReference();
-  std::swap(theFlags, lOtherItem->theFlags);
-  if(lHasReference)
-  {
-    setHaveReference();
-  }
-  if(lOtherHasReference)
-  {
-    setHaveReference();
-  }
-  
-  // Swap root nodes and adjust type maps.
+  // But some things must be "unswapped"
+  std::swap(getTree()->thePos, lOtherItem->getTree()->thePos);
+  std::swap(getTree()->theId, lOtherItem->getTree()->theId);
+  std::swap(getTree()->theCollection, lOtherItem->getTree()->theCollection);
+
+  // Before unswapping root nodes as well, their references in the type maps
+  // must be erased.
   store::Item_t lRootNodeType;
   store::Item_t lOtherRootNodeType;
   bool lRootHasType = getTree()->theTypesMap->get(
@@ -796,7 +789,11 @@
     lOtherItem->getTree()->theTypesMap->erase(
         lOtherItem->getTree()->theRootNode);
   }
+
+  // Now unswapping root nodes.
   std::swap(getTree()->theRootNode, lOtherItem->getTree()->theRootNode);
+
+  // And putting references back into the type maps.
   if(lRootHasType)
   {
     getTree()->theTypesMap->insert(getTree()->theRootNode, lRootNodeType);
@@ -807,10 +804,19 @@
         lOtherItem->getTree()->theRootNode, lOtherRootNodeType);
   }
 
-  // Adjust trees.
-#ifndef EMBEDED_TYPE
-  std::swap(getTree()->theTypesMap, lOtherItem->getTree()->theTypesMap);
-#endif
+  // Swap flags expect hasReference.
+  bool lHasReference = haveReference();
+  bool lOtherHasReference = lOtherItem->haveReference();
+  std::swap(theFlags, lOtherItem->theFlags);
+  if(lHasReference)
+  {
+    setHaveReference();
+  }
+  if(lOtherHasReference)
+  {
+    setHaveReference();
+  }
+
 }
 
 /*******************************************************************************


Follow ups