jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1433482 - in /jackrabbit/oak/trunk/oak-mk/src: main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java test/java/org/apache/jackrabbit/mk/MicroKernelImplTest.java
Date Tue, 15 Jan 2013 16:06:40 GMT
Author: thomasm
Date: Tue Jan 15 16:06:39 2013
New Revision: 1433482

URL: http://svn.apache.org/viewvc?rev=1433482&view=rev
Log:
OAK-548 Moving larger trees cause OutOfMemoryError (diff ignores depth for added nodes)

Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/MicroKernelImplTest.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java?rev=1433482&r1=1433481&r2=1433482&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java
Tue Jan 15 16:06:39 2013
@@ -60,7 +60,7 @@ public class DiffBuilder {
         if (before == null) {
             if (after != null) {
                 buff.tag('+').key(path).object();
-                toJson(buff, after);
+                toJson(buff, after, depth);
                 return buff.endObject().newline().toString();
             } else {
                 // path doesn't exist in the specified revisions
@@ -117,7 +117,7 @@ public class DiffBuilder {
                     addedNodes.put(after, p);
                     buff.tag('+').
                             key(p).object();
-                    toJson(buff, after);
+                    toJson(buff, after, depth);
                     buff.endObject().newline();
                 }
             }
@@ -215,7 +215,7 @@ public class DiffBuilder {
                     if (p.startsWith(pathFilter)) {
                         buff.tag('+').
                                 key(p).object();
-                        toJson(buff, after);
+                        toJson(buff, after, depth);
                         buff.endObject().newline();
                     }
                 }
@@ -267,14 +267,16 @@ public class DiffBuilder {
         return buff.toString();
     }
 
-    private void toJson(JsopBuilder builder, NodeState node) {
+    private void toJson(JsopBuilder builder, NodeState node, int depth) {
         for (PropertyState property : node.getProperties()) {
             builder.key(property.getName()).encodedValue(property.getEncodedValue());
         }
-        for (ChildNode entry : node.getChildNodeEntries(0, -1)) {
-            builder.key(entry.getName()).object();
-            toJson(builder, entry.getNode());
-            builder.endObject();
+        if (depth != 0) {
+            for (ChildNode entry : node.getChildNodeEntries(0, -1)) {
+                builder.key(entry.getName()).object();
+                toJson(builder, entry.getNode(), depth < 0 ? depth : depth - 1);
+                builder.endObject();
+            }
         }
     }
 }

Modified: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/MicroKernelImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/MicroKernelImplTest.java?rev=1433482&r1=1433481&r2=1433482&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/MicroKernelImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/MicroKernelImplTest.java
Tue Jan 15 16:06:39 2013
@@ -63,4 +63,15 @@ public class MicroKernelImplTest {
         headRev = mk.commit("/", "+\"b\" : {}", mk.getHeadRevision(), null);
         assertFalse("Commit must not have same id as branch", headRev.equals(branchRev));
     }
+    
+    @Test
+    public void diffWithDepth() {
+        String head = mk.getHeadRevision();
+        String r1 = mk.commit("/", "+\"a\" : { \"l\": 1, \"x\": { \"l\": 2, \"y\": {} } }",
head, null);
+        String r2 = mk.commit("/", ">\"a\" : \"b\"", r1, null);
+        assertEquals("+\"/b\":{\"l\":1}", mk.diff(r1, r2, "/b", 0).trim());
+        assertEquals("+\"/b\":{\"l\":1,\"x\":{\"l\":2}}", mk.diff(r1, r2, "/b", 1).trim());
+        assertEquals("+\"/b\":{\"l\":1,\"x\":{\"l\":2,\"y\":{}}}", mk.diff(r1, r2, "/b",
-1).trim());
+    }
+
 }



Mime
View raw message