jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meteata...@apache.org
Subject svn commit: r1430348 - /jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
Date Tue, 08 Jan 2013 16:07:25 GMT
Author: meteatamel
Date: Tue Jan  8 16:07:24 2013
New Revision: 1430348

URL: http://svn.apache.org/viewvc?rev=1430348&view=rev
Log:
OAK-535 - MergeCommand reads complete tree into memory

Removed one of the getNodes call by reusing the result of a previous getNodes call

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java?rev=1430348&r1=1430347&r2=1430348&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/impl/command/MergeCommand.java
Tue Jan  8 16:07:24 2013
@@ -1,5 +1,6 @@
 package org.apache.jackrabbit.mongomk.impl.command;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -66,9 +67,8 @@ public class MergeCommand extends BaseCo
         long branchRootId = Long.parseLong(branchId.substring(0, branchId.indexOf("-")));
 
         // Merge nodes from head to branch.
-        ourRoot = mergeNodes(ourRoot, currentHead, branchRootId);
-
         Node currentHeadNode = getNode("/", currentHead);
+        ourRoot = mergeNodes(ourRoot, currentHeadNode, branchRootId);
 
         String diff = new DiffBuilder(MongoUtil.wrap(currentHeadNode),
                 MongoUtil.wrap(ourRoot), "/", -1,
@@ -88,14 +88,14 @@ public class MergeCommand extends BaseCo
         return MongoUtil.fromMongoRepresentation(revision);
     }
 
-    private NodeImpl mergeNodes(Node ourRoot, Long newBaseRevisionId,
+    private NodeImpl mergeNodes(Node ourRoot, Node theirRoot,
             Long commonAncestorRevisionId) throws Exception {
 
         Node baseRoot = getNode("/", commonAncestorRevisionId);
-        Node theirRoot = getNode("/", newBaseRevisionId);
+        Node theirRootCopy = copy(theirRoot);
 
         // Recursively merge 'our' changes with 'their' changes...
-        NodeImpl mergedNode = mergeNode(baseRoot, ourRoot, theirRoot, "/");
+        NodeImpl mergedNode = mergeNode(baseRoot, ourRoot, theirRootCopy, "/");
 
         return mergedNode;
     }
@@ -182,4 +182,17 @@ public class MergeCommand extends BaseCo
         command.setBranchId(branchId);
         return command.execute();
     }
+
+    private NodeImpl copy(Node node) {
+        NodeImpl copy = new NodeImpl(node.getPath());
+        copy.setRevisionId(node.getRevisionId());
+        for (Map.Entry<String, String> entry : node.getProperties().entrySet()) {
+            copy.addProperty(entry.getKey(), entry.getValue());
+        }
+        for (Iterator<Node> it = node.getChildNodeEntries(0, -1); it.hasNext(); ) {
+            Node child = it.next();
+            copy.addChildNodeEntry(copy(child));
+        }
+        return copy;
+    }
 }
\ No newline at end of file



Mime
View raw message