jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1369019 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/mk/index/ oak-core/src/main/java/org/apache/jackrabbit/mk/simple/ oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/ oak-it/mk/src/main/java/org/apache/...
Date Fri, 03 Aug 2012 15:18:11 GMT
Author: stefan
Date: Fri Aug  3 15:18:11 2012
New Revision: 1369019

URL: http://svn.apache.org/viewvc?rev=1369019&view=rev
Log:
OAK-227: MicroKernel API: add depth parameter to diff method

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
    jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/client/Client.java
    jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/tree/DiffBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
Fri Aug  3 15:18:11 2012
@@ -172,8 +172,8 @@ public class IndexWrapper extends MicroK
     }
 
     @Override
-    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path)
{
-        return mk.diffStream(fromRevisionId, toRevisionId, path);
+    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path,
int depth) {
+        return mk.diffStream(fromRevisionId, toRevisionId, path, depth);
     }
 
     @Override
@@ -182,11 +182,6 @@ public class IndexWrapper extends MicroK
     }
 
     @Override
-    public JsopReader getNodesStream(String path, String revisionId) {
-        return getNodesStream(path, revisionId, 1, 0, -1, null);
-    }
-
-    @Override
     public JsopReader getRevisionsStream(long since, int maxEntries, String path) {
         return mk.getRevisionsStream(since, maxEntries, path);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
Fri Aug  3 15:18:11 2012
@@ -453,7 +453,7 @@ public class SimpleKernelImpl extends Mi
 
 
     @Override
-    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path)
{
+    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path,
int depth) {
         fromRevisionId = fromRevisionId == null ? headRevision : fromRevisionId;
         toRevisionId = toRevisionId == null ? headRevision : toRevisionId;
         // TODO implement if required
@@ -471,11 +471,6 @@ public class SimpleKernelImpl extends Mi
      * @return the json string
      */
     @Override
-    public JsopReader getNodesStream(String path, String revisionId) {
-        return getNodesStream(path, revisionId, 1, 0, -1, null);
-    }
-
-    @Override
     public JsopReader getNodesStream(String path, String revisionId, int depth, long offset,
int count, String filter) {
         revisionId = revisionId == null ? headRevision : revisionId;
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
Fri Aug  3 15:18:11 2012
@@ -82,10 +82,10 @@ public class LogWrapper implements Micro
     }
 
     @Override
-    public String diff(String fromRevisionId, String toRevisionId, String path) {
+    public String diff(String fromRevisionId, String toRevisionId, String path, int depth)
{
         try {
             logMethod("diff", fromRevisionId, toRevisionId, path);
-            String result = mk.diff(fromRevisionId, toRevisionId, path);
+            String result = mk.diff(fromRevisionId, toRevisionId, path, depth);
             logResult(result);
             return result;
         } catch (Exception e) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapper.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapper.java
Fri Aug  3 15:18:11 2012
@@ -30,12 +30,10 @@ public interface MicroKernelWrapper exte
 
     JsopReader getJournalStream(String fromRevisionId, String toRevisionId, String path)
throws MicroKernelException;
 
-    JsopReader getNodesStream(String path, String revisionId) throws MicroKernelException;
-
     JsopReader getNodesStream(String path, String revisionId, int depth, long offset, int
count, String filter) throws MicroKernelException;
 
     String commitStream(String path, JsopReader jsonDiff, String revisionId, String message)
throws MicroKernelException;
 
-    JsopReader diffStream(String fromRevisionId, String toRevisionId, String path);
+    JsopReader diffStream(String fromRevisionId, String toRevisionId, String path, int depth);
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
Fri Aug  3 15:18:11 2012
@@ -50,8 +50,8 @@ public abstract class MicroKernelWrapper
     }
 
     @Override
-    public final String diff(String fromRevisionId, String toRevisionId, String path) {
-        return diffStream(fromRevisionId, toRevisionId, path).toString();
+    public final String diff(String fromRevisionId, String toRevisionId, String path, int
depth) {
+        return diffStream(fromRevisionId, toRevisionId, path, depth).toString();
     }
 
     @Override
@@ -115,16 +115,6 @@ public abstract class MicroKernelWrapper
         }
 
         @Override
-        public JsopReader getNodesStream(String path, String revisionId) {
-            String json = wrapped.getNodes(path, revisionId, 1, 0, -1, null);
-            if (json != null) {
-                return new JsopTokenizer(json);
-            } else {
-                return null;
-            }
-        }
-
-        @Override
         public JsopReader getNodesStream(String path, String revisionId, int depth, long
offset, int count, String filter) {
             String json = wrapped.getNodes(
                     path, revisionId, depth, offset, count, filter);
@@ -141,8 +131,8 @@ public abstract class MicroKernelWrapper
         }
 
         @Override
-        public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path)
{
-            return new JsopTokenizer(wrapped.diff(fromRevisionId, toRevisionId, path));
+        public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path,
int depth) {
+            return new JsopTokenizer(wrapped.diff(fromRevisionId, toRevisionId, path, depth));
         }
 
         @Override
@@ -161,8 +151,8 @@ public abstract class MicroKernelWrapper
         }
 
         @Override
-        public String diff(String fromRevisionId, String toRevisionId, String path) {
-            return wrapped.diff(fromRevisionId, toRevisionId, path);
+        public String diff(String fromRevisionId, String toRevisionId, String path, int depth)
{
+            return wrapped.diff(fromRevisionId, toRevisionId, path, depth);
         }
 
         @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
Fri Aug  3 15:18:11 2012
@@ -150,9 +150,9 @@ public class SecurityWrapper extends Mic
     }
 
     @Override
-    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path)
{
+    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path,
int depth) {
         rightsRevision = getHeadRevision();
-        JsopReader diff = mk.diffStream(fromRevisionId, toRevisionId, path);
+        JsopReader diff = mk.diffStream(fromRevisionId, toRevisionId, path, depth);
         if (admin) {
             return diff;
         }
@@ -285,11 +285,6 @@ public class SecurityWrapper extends Mic
     }
 
     @Override
-    public JsopReader getNodesStream(String path, String revisionId) {
-        return getNodesStream(path, revisionId, 1, 0, -1, null);
-    }
-
-    @Override
     public JsopReader getNodesStream(String path, String revisionId, int depth, long offset,
int count, String filter) {
         rightsRevision = getHeadRevision();
         if (!checkRights(path, false)) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
Fri Aug  3 15:18:11 2012
@@ -261,8 +261,8 @@ public class VirtualRepositoryWrapper ex
     }
 
     @Override
-    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path)
throws MicroKernelException {
-        return mk.diffStream(fromRevisionId, toRevisionId, path);
+    public JsopReader diffStream(String fromRevisionId, String toRevisionId, String path,
int depth) throws MicroKernelException {
+        return mk.diffStream(fromRevisionId, toRevisionId, path, depth);
     }
 
     @Override
@@ -271,11 +271,6 @@ public class VirtualRepositoryWrapper ex
     }
 
     @Override
-    public JsopReader getNodesStream(String path, String revisionId) {
-        return getNodesStream(path, revisionId, 1, 0, -1, null);
-    }
-
-    @Override
     public JsopReader getNodesStream(String path, String revisionId, int depth, long offset,
int count, String filter) {
         String mount = getMount(path);
         if (mount == null) {

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Fri Aug  3 15:18:11 2012
@@ -210,7 +210,7 @@ public class MicroKernelIT extends Abstr
         assertTrue(mk.nodeExists("/test/target", null));
 
         // get reverse diff
-        String reverseDiff = mk.diff(rev1, rev0, null);
+        String reverseDiff = mk.diff(rev1, rev0, null, -1);
         assertNotNull(reverseDiff);
         assertTrue(reverseDiff.length() > 0);
 
@@ -219,7 +219,7 @@ public class MicroKernelIT extends Abstr
         assertFalse(mk.nodeExists("/test/target", null));
 
         // diff of rev0->rev2 should be empty
-        assertEquals("", mk.diff(rev0, rev2, null));
+        assertEquals("", mk.diff(rev0, rev2, null, -1));
     }
 
     @Test
@@ -230,7 +230,7 @@ public class MicroKernelIT extends Abstr
         String rev2 = mk.commit("/test/bar", "^\"p2\":456", null, "");
 
         // test with path filter
-        String diff = mk.diff(rev0, rev2, "/test");
+        String diff = mk.diff(rev0, rev2, "/test", -1);
         assertNotNull(diff);
         assertFalse(diff.isEmpty());
         assertTrue(diff.contains("foo"));
@@ -238,7 +238,7 @@ public class MicroKernelIT extends Abstr
         assertTrue(diff.contains("123"));
         assertTrue(diff.contains("456"));
 
-        diff = mk.diff(rev0, rev2, "/test/foo");
+        diff = mk.diff(rev0, rev2, "/test/foo", -1);
         assertNotNull(diff);
         assertFalse(diff.isEmpty());
         assertTrue(diff.contains("foo"));
@@ -247,12 +247,55 @@ public class MicroKernelIT extends Abstr
         assertFalse(diff.contains("456"));
 
         // non-matching filter
-        diff = mk.diff(rev0, rev2, "/blah");
+        diff = mk.diff(rev0, rev2, "/blah", -1);
         assertNotNull(diff);
         assertTrue(diff.isEmpty());
     }
 
     @Test
+    public void diffDepthLimited() {
+        // initial content (/test/foo)
+        String rev0 = mk.commit("/test", "+\"foo\":{}", null, "");
+
+        // add /test/foo/bar
+        String rev1 = mk.commit("/test/foo", "+\"bar\":{\"p1\":123}", null, "");
+
+        // modify property /test/foo/bar/p1
+        String rev2 = mk.commit("/test/foo/bar", "^\"p1\":456", null, "");
+
+        // diff with depth -1
+        assertEquals(mk.diff(rev0, rev2, "/", Integer.MAX_VALUE), mk.diff(rev0, rev2, "/",
-1));
+
+        // diff with depth 5
+        String diff = mk.diff(rev0, rev2, "/", 5);
+        // returned +"/test/foo/bar":{"p1":456}
+        assertNotNull(diff);
+        assertFalse(diff.isEmpty());
+        assertTrue(diff.contains("/test/foo/bar"));
+        assertTrue(diff.contains("456"));
+
+        // diff with depth 0
+        diff = mk.diff(rev0, rev2, "/", 0);
+        // returned ^"/test", indicating that there are changes below /test
+        assertNotNull(diff);
+        assertFalse(diff.isEmpty());
+        assertFalse(diff.contains("/test/foo"));
+        assertFalse(diff.contains("456"));
+        assertTrue(diff.contains("/test"));
+        assertTrue(diff.startsWith("^"));
+
+        // diff with depth 1
+        diff = mk.diff(rev0, rev2, "/", 1);
+        // returned ^"/test/foo", indicating that there are changes below /test/foo
+        assertNotNull(diff);
+        assertFalse(diff.isEmpty());
+        assertFalse(diff.contains("/test/foo/bar"));
+        assertFalse(diff.contains("456"));
+        assertTrue(diff.contains("/test/foo"));
+        assertTrue(diff.startsWith("^"));
+    }
+
+    @Test
     public void snapshotIsolation() {
         final int NUM_COMMITS = 1000;
 

Modified: jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Fri Aug  3 15:18:11 2012
@@ -103,7 +103,7 @@ public interface MicroKernel {
      * @param maxEntries maximum #entries to be returned;
      *                   if < 0, no limit will be applied.
      * @param path       optional path filter; if {@code null} or {@code ""} the
-     *                   default ({@code"/"}) will be assumed, i.e. no filter
+     *                   default ({@code "/"}) will be assumed, i.e. no filter
      *                   will be applied
      * @return a list of revisions in chronological order in JSON format.
      * @throws MicroKernelException if an error occurs
@@ -165,7 +165,7 @@ public interface MicroKernel {
      * @param toRevisionId   id of last revision to be returned in journal,
      *                       if {@code null} the current head revision is assumed
      * @param path           optional path filter; if {@code null} or {@code ""}
-     *                       the default ({@code"/"}) will be assumed, i.e. no
+     *                       the default ({@code "/"}) will be assumed, i.e. no
      *                       filter will be applied
      * @return a chronological list of revisions in JSON format
      * @throws MicroKernelException if an error occurs
@@ -183,17 +183,41 @@ public interface MicroKernel {
      * The {@code path} parameter allows to filter the changes included in the
      * JSON diff, i.e. only those changes that affected the subtree rooted at
      * {@code path} will be included.
+     * <p/>
+     * The {@code depth} limit applies to the subtree rooted at {@code path}.
+     * It allows to limit the depth of the diff, i.e. only changes up to the
+     * specified depth will be included in full detail. changes at paths exceeding
+     * the specified depth limit will be reported as {@code ^"/some/path"},
+     * indicating that there are unspecified changes below that path.
+     * <table border="1">
+     *   <tr>
+     *     <th>{@code depth} value</th><th>scope of detailed diff</th>
+     *    </tr>
+     *    <tr>
+     *      <td>-1</td><td>no limit will be applied</td>
+     *    </tr>
+     *    <tr>
+     *      <td>0</td><td>changes affecting the properties and child node
names of the node at {@code path}</td>
+     *    </tr>
+     *    <tr>
+     *      <td>1</td><td>changes affecting the properties and child node
names of the node at {@code path} and its direct descendants</td>
+     *    </tr>
+     *    <tr>
+     *      <td>...</td><td>...</td>
+     *    </tr>
+     * </table>
      *
      * @param fromRevisionId a revision id, if {@code null} the current head revision is
assumed
      * @param toRevisionId   another revision id, if {@code null} the current head revision
is assumed
      * @param path           optional path filter; if {@code null} or {@code ""}
-     *                       the default ({@code"/"}) will be assumed, i.e. no
+     *                       the default ({@code "/"}) will be assumed, i.e. no
      *                       filter will be applied
+     * @param depth          depth  limit; if {@code -1} no limit will be applied
      * @return JSON diff representation of the changes
      * @throws MicroKernelException if an error occurs
      */
     String /* JSON diff */ diff(String fromRevisionId, String toRevisionId,
-                                String path)
+                                String path, int depth)
             throws MicroKernelException;
 
     //-------------------------------------------------------------< READ ops >
@@ -287,7 +311,7 @@ public interface MicroKernel {
      * specified.
      * <p/>
      * The order of the child nodes is stable for any given {@code revisionId},
-     * i.e. calling {@link #getNodes} repeatedly with the same {@code revisionId}
+     * i.e. calling {@code getNodes} repeatedly with the same {@code revisionId}
      * is guaranteed to return the child nodes in the same order, but the
      * specific order used is implementation-dependent and may change across
      * different revisions of the same node.

Modified: jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/client/Client.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/client/Client.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/client/Client.java
(original)
+++ jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/client/Client.java
Fri Aug  3 15:18:11 2012
@@ -166,7 +166,7 @@ public class Client implements MicroKern
     }
 
     @Override
-    public String diff(String fromRevisionId, String toRevisionId, String path)
+    public String diff(String fromRevisionId, String toRevisionId, String path, int depth)
             throws MicroKernelException {
         Request request = null;
 
@@ -175,6 +175,7 @@ public class Client implements MicroKern
             request.addParameter("from_revision_id", fromRevisionId);
             request.addParameter("to_revision_id", toRevisionId);
             request.addParameter("path", path);
+            request.addParameter("depth", depth);
             return request.getString();
         } catch (IOException e) {
             throw toMicroKernelException(e);

Modified: jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/oak/trunk/oak-mk-remote/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Fri Aug  3 15:18:11 2012
@@ -175,9 +175,10 @@ class MicroKernelServlet {
             String fromRevisionId = request.getParameter("from_revision_id", headRevision);
             String toRevisionId = request.getParameter("to_revision_id", headRevision);
             String path = request.getParameter("path", "");
+            int depth = request.getParameter("depth", 1);
 
             response.setContentType("application/json");
-            String json = mk.diff(fromRevisionId, toRevisionId, path);
+            String json = mk.diff(fromRevisionId, toRevisionId, path, depth);
             if (request.getHeaders().containsKey("User-Agent")) {
                 json = JsopBuilder.prettyPrint(json);
             }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
Fri Aug  3 15:18:11 2012
@@ -130,7 +130,7 @@ public class MicroKernelImpl implements 
                         String diff = new DiffBuilder(
                                 rep.getNodeState(commit.getParentId(), "/"),
                                 rep.getNodeState(commit.getId(), "/"),
-                                "/", rep.getRevisionStore(), path).build();
+                                "/", -1, rep.getRevisionStore(), path).build();
                         if (!diff.isEmpty()) {
                             history.add(commit);
                         }
@@ -237,7 +237,7 @@ public class MicroKernelImpl implements 
                     diff = new DiffBuilder(
                             rep.getNodeState(commit.getParentId(), "/"),
                             rep.getNodeState(commit.getId(), "/"),
-                            "/", rep.getRevisionStore(), path).build();
+                            "/", -1, rep.getRevisionStore(), path).build();
                     if (diff.isEmpty()) {
                         continue;
                     }
@@ -254,9 +254,13 @@ public class MicroKernelImpl implements 
         return commitBuff.endArray().toString();
     }
 
-    public String diff(String fromRevision, String toRevision, String path) throws MicroKernelException
{
+    public String diff(String fromRevision, String toRevision, String path, int depth) throws
MicroKernelException {
         path = (path == null || "".equals(path)) ? "/" : path;
 
+        if (depth < -1) {
+            throw new IllegalArgumentException("depth");
+        }
+
         Id fromRevisionId, toRevisionId;
         if (fromRevision == null || toRevision == null) {
             Id head = getHeadRevisionId();
@@ -283,7 +287,7 @@ public class MicroKernelImpl implements 
             NodeState before = rep.getNodeState(fromRevisionId, path);
             NodeState after = rep.getNodeState(toRevisionId, path);
 
-            return new DiffBuilder(before, after, path, rep.getRevisionStore(), path).build();
+            return new DiffBuilder(before, after, path, depth, rep.getRevisionStore(), path).build();
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java?rev=1369019&r1=1369018&r2=1369019&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Fri Aug  3 15:18:11 2012
@@ -224,7 +224,7 @@ public class CommitBuilder {
             String diff = new DiffBuilder(
                     store.getNodeState(store.getRootNode(currentHead)),
                     store.getNodeState(store.getNode(rootNodeId)),
-                    "/", store, "").build();
+                    "/", -1, store, "").build();
             newCommit.setChanges(diff);
             newCommit.setRootNodeId(rootNodeId);
             newCommit.setBranchRootId(null);

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=1369019&r1=1369018&r2=1369019&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
Fri Aug  3 15:18:11 2012
@@ -30,17 +30,18 @@ public class DiffBuilder {
     private final NodeState before;
     private final NodeState after;
     private final String path;
+    private final int depth;
     private final String pathFilter;
     private final NodeStore store;
 
-    public DiffBuilder(NodeState before, NodeState after, String path,
+    public DiffBuilder(NodeState before, NodeState after, String path, int depth,
                        NodeStore store, String pathFilter) {
         this.before = before;
         this.after = after;
         this.path = path;
+        this.depth = depth;
         this.store = store;
         this.pathFilter = (pathFilter == null || "".equals(pathFilter)) ? "/" : pathFilter;
-
     }
 
     public String build() throws Exception {
@@ -72,6 +73,7 @@ public class DiffBuilder {
         }
 
         TraversingNodeDiffHandler diffHandler = new TraversingNodeDiffHandler(store) {
+            int levels = depth < 0 ? Integer.MAX_VALUE : depth;
             @Override
             public void propertyAdded(PropertyState after) {
                 String p = PathUtils.concat(getCurrentPath(), after.getName());
@@ -136,7 +138,16 @@ public class DiffBuilder {
                 String p = PathUtils.concat(getCurrentPath(), name);
                 if (PathUtils.isAncestor(p, pathFilter)
                         || p.startsWith(pathFilter)) {
-                    super.childNodeChanged(name, before, after);
+                    --levels;
+                    if (levels >= 0) {
+                        // recurse
+                        super.childNodeChanged(name, before, after);
+                    } else {
+                        buff.tag('^');
+                        buff.value(p);
+                        buff.newline();
+                    }
+                    ++levels;
                 }
             }
         };
@@ -156,6 +167,7 @@ public class DiffBuilder {
             // TODO refactor code, avoid duplication
 
             diffHandler = new TraversingNodeDiffHandler(store) {
+                int levels = depth < 0 ? Integer.MAX_VALUE : depth;
                 @Override
                 public void propertyAdded(PropertyState after) {
                     String p = PathUtils.concat(getCurrentPath(), after.getName());
@@ -226,7 +238,16 @@ public class DiffBuilder {
                     String p = PathUtils.concat(getCurrentPath(), name);
                     if (PathUtils.isAncestor(p, pathFilter)
                             || p.startsWith(pathFilter)) {
-                        super.childNodeChanged(name, before, after);
+                        --levels;
+                        if (levels >= 0) {
+                            // recurse
+                            super.childNodeChanged(name, before, after);
+                        } else {
+                            buff.tag('^');
+                            buff.value(p);
+                            buff.newline();
+                        }
+                        ++levels;
                     }
                 }
             };



Mime
View raw message