jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1327973 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/mk/client/ oak-core/src/main/java/org/apache/jackrabbit/mk/index/ oak-core/src/main/java/org/apache/jackrabbit/mk/server/ oak-core/src/main/java/org/apache/ja...
Date Thu, 19 Apr 2012 14:46:30 GMT
Author: stefan
Date: Thu Apr 19 14:46:29 2012
New Revision: 1327973

URL: http://svn.apache.org/viewvc?rev=1327973&view=rev
Log:
 OAK-45: Add support for branching and merging of private copies to MicroKernel (WIP)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
    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/server/MicroKernelServlet.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/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-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java?rev=1327973&r1=1327972&r2=1327973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/client/Client.java
Thu Apr 19 14:46:29 2012
@@ -266,6 +266,39 @@ public class Client implements MicroKern
         }
     }
 
+    public synchronized String branch(String trunkRevisionId)
+            throws MicroKernelException {
+
+        Request request = null;
+
+        try {
+            request = createRequest("branch");
+            request.addParameter("trunk_revision_id", trunkRevisionId);
+            return request.getString();
+        } catch (IOException e) {
+            throw toMicroKernelException(e);
+        } finally {
+            IOUtils.closeQuietly(request);
+        }
+    }
+
+    public synchronized String merge(String branchRevisionId, String message)
+            throws MicroKernelException {
+
+        Request request = null;
+
+        try {
+            request = createRequest("merge");
+            request.addParameter("branch_revision_id", branchRevisionId);
+            request.addParameter("message", message);
+            return request.getString();
+        } catch (IOException e) {
+            throw toMicroKernelException(e);
+        } finally {
+            IOUtils.closeQuietly(request);
+        }
+    }
+
     public synchronized long getLength(String blobId) throws MicroKernelException {
         Request request = null;
 

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -80,6 +80,14 @@ public class IndexWrapper extends MicroK
         return mk.write(in);
     }
 
+    public String branch(String trunkRevisionId) {
+        return mk.branch(trunkRevisionId);
+    }
+
+    public String merge(String branchRevisionId, String message) {
+        return mk.merge(branchRevisionId, message);
+    }
+
     public String commitStream(String rootPath, JsopReader jsonDiff, String revisionId, String
message) {
         if (!rootPath.startsWith(INDEX_PATH)) {
             String rev = mk.commitStream(rootPath, jsonDiff, revisionId, message);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1327973&r1=1327972&r2=1327973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Thu Apr 19 14:46:29 2012
@@ -82,6 +82,8 @@ class MicroKernelServlet {
         COMMANDS.put("getChildNodeCount", new GetChildNodeCount());
         COMMANDS.put("getNodes", new GetNodes());
         COMMANDS.put("commit", new Commit());
+        COMMANDS.put("branch", new Branch());
+        COMMANDS.put("merge", new Merge());
         COMMANDS.put("getLength", new GetLength());
         COMMANDS.put("read", new Read());
         COMMANDS.put("write", new Write());
@@ -253,6 +255,37 @@ class MicroKernelServlet {
         }        
     }
 
+    static class Branch implements Command {
+
+        public void execute(MicroKernel mk, Request request, Response response)
+                throws IOException, MicroKernelException {
+
+            String headRevision = mk.getHeadRevision();
+
+            String trunkRevisionId = request.getParameter("trunk_revision_id", headRevision);
+
+            String newRevision = mk.branch(trunkRevisionId);
+
+            response.setContentType("text/plain");
+            response.write(newRevision);
+        }
+    }
+
+    static class Merge implements Command {
+
+        public void execute(MicroKernel mk, Request request, Response response)
+                throws IOException, MicroKernelException {
+
+            String branchRevisionId = request.getParameter("branch_revision_id");
+            String message = request.getParameter("message");
+
+            String newRevision = mk.merge(branchRevisionId, message);
+
+            response.setContentType("text/plain");
+            response.write(newRevision);
+        }
+    }
+
     static class GetLength implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mk.simple;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.blobs.AbstractBlobStore;
 import org.apache.jackrabbit.mk.blobs.FileBlobStore;
 import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
@@ -567,4 +568,13 @@ public class SimpleKernelImpl extends Mi
         return "simple:" + name;
     }
 
+    public String branch(String trunkRevisionId) throws MicroKernelException {
+        // TODO OAK-45 support
+        throw new UnsupportedOperationException();
+    }
+
+    public String merge(String branchRevisionId, String message) throws MicroKernelException
{
+        // TODO OAK-45 support
+        throw new UnsupportedOperationException();
+    }
 }

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -207,6 +207,30 @@ public class LogWrapper implements Micro
         }
     }
 
+    public String branch(String trunkRevisionId) {
+        try {
+            logMethod("branch", trunkRevisionId);
+            String result = mk.branch(trunkRevisionId);
+            logResult(result);
+            return result;
+        } catch (Exception e) {
+            logException(e);
+            throw convert(e);
+        }
+    }
+
+    public String merge(String branchRevisionId, String message) {
+        try {
+            logMethod("merge", branchRevisionId, message);
+            String result = mk.merge(branchRevisionId, message);
+            logResult(result);
+            return result;
+        } catch (Exception e) {
+            logException(e);
+            throw convert(e);
+        }
+    }
+
     private void logMethod(String methodName, Object... args) {
         StringBuilder buff = new StringBuilder("mk");
         buff.append(id).append('.').append(methodName).append('(');

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -117,6 +117,14 @@ public abstract class MicroKernelWrapper
                 return wrapped.commit(path, jsonDiff, revisionId, message);
             }
 
+            public String branch(String trunkRevisionId) {
+                return wrapped.branch(trunkRevisionId);
+            }
+
+            public String merge(String branchRevisionId, String message) {
+                return wrapped.merge(branchRevisionId, message);
+            }
+
             public String diff(String fromRevisionId, String toRevisionId, String path) {
                 return wrapped.diff(fromRevisionId, toRevisionId, path);
             }

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -334,6 +334,16 @@ public class SecurityWrapper extends Mic
         return mk.write(in);
     }
 
+    public String branch(String trunkRevisionId) {
+        // TODO OAK-45 support
+        return mk.branch(trunkRevisionId);
+    }
+
+    public String merge(String branchRevisionId, String message) {
+        // TODO OAK-45 support
+        return mk.merge(branchRevisionId, message);
+    }
+
     private NodeImpl filterAccess(String path, NodeImpl n) {
         if (!checkRights(path, false)) {
             return null;

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -324,5 +324,14 @@ public class VirtualRepositoryWrapper ex
         return mk.write(in);
     }
 
+    public String branch(String trunkRevisionId) {
+        // TODO OAK-45 support
+        return mk.branch(trunkRevisionId);
+    }
+
+    public String merge(String branchRevisionId, String message) {
+        // TODO OAK-45 support
+        return mk.merge(branchRevisionId, message);
+    }
 }
 

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1327973&r1=1327972&r2=1327973&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Thu Apr 19 14:46:29 2012
@@ -109,7 +109,8 @@ public interface MicroKernel {
      * </pre>
      *
      * @param fromRevisionId id of first revision to be returned in journal
-     * @param toRevisionId   id of last revision to be returned in journal, if {@code null}
the current head revision is assumed
+     * @param toRevisionId   id of last revision to be returned in journal,
+     *                       if {@code null} the current head revision is assumed
      * @param filter         (optional) filter criteria
      *                       (e.g. path, property names, etc);
      *                       TODO specify format and semantics
@@ -262,7 +263,8 @@ public interface MicroKernel {
      *
      * @param path path denoting target node
      * @param jsonDiff changes to be applied in JSON diff format.
-     * @param revisionId id of revision the changes are based on, if {@code null} the current
head revision is assumed
+     * @param revisionId id of revision the changes are based on,
+     *                   if {@code null} the current head revision is assumed
      * @param message commit message
      * @return id of newly created revision
      * @throws MicroKernelException if an error occurs
@@ -270,6 +272,45 @@ public interface MicroKernel {
     String /* revisionId */ commit(String path, String jsonDiff, String revisionId, String
message)
             throws MicroKernelException;
 
+    /**
+     * Creates a <i>private</i> branch revision off the specified <i>public</i>
+     * trunk revision.
+     * <p/>
+     * A {@code MicroKernelException} is thrown if {@code trunkRevisionId} doesn't
+     * exist, if it's not a <i>trunk</i> revision (i.e. it's not reachable
+     * by traversing the revision history backwards starting from the current
+     * head revision) or if another error occurs.
+     *
+     * @param trunkRevisionId id of public trunk revision to base branch on,
+     *                        if {@code null} the current head revision is assumed
+     * @return id of newly created private branch revision
+     * @throws MicroKernelException if {@code trunkRevisionId} doesn't exist,
+     *                              if it's not a <i>trunk</i> revision
+     *                              or if another error occurs
+     * @see #merge(String, String)
+     */
+    String /* revisionId */ branch(String trunkRevisionId)
+            throws MicroKernelException;
+
+    /**
+     * Merges the specified <i>private</i> branch revision with the current
+     * head revision.
+     * <p/>
+     * A {@code MicroKernelException} is thrown if {@code branchRevisionId} doesn't
+     * exist, if it's not a branch revision, if the merge fails because of
+     * conflicting changes or if another error occurs.
+     *
+     * @param branchRevisionId id of private branch revision
+     * @param message commit message
+     * @return id of newly created head revision
+     * @throws MicroKernelException if {@code branchRevisionId} doesn't exist,
+     *                              if it's not a branch revision, if the merge
+     *                              fails because of conflicting changes or if
+     *                              another error occurs.
+     * @see #branch(String)
+     */
+    String /* revisionId */ merge(String branchRevisionId, String message)
+            throws MicroKernelException;
 
     //--------------------------------------------------< BLOB READ/WRITE ops >
 

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=1327973&r1=1327972&r2=1327973&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
Thu Apr 19 14:46:29 2012
@@ -411,14 +411,14 @@ public class MicroKernelImpl implements 
         }
     }
 
-    public String branch(String publicRevisionId) throws MicroKernelException {
+    public String branch(String trunkRevisionId) throws MicroKernelException {
         // create a private branch
 
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
 
-        Id revId = publicRevisionId == null ? getHeadRevisionId() : Id.fromString(publicRevisionId);
+        Id revId = trunkRevisionId == null ? getHeadRevisionId() : Id.fromString(trunkRevisionId);
 
         try {
             CommitBuilder cb = rep.getCommitBuilder(revId, "");
@@ -428,18 +428,17 @@ public class MicroKernelImpl implements 
         }
     }
 
-    public String merge(String privateRevisionId) throws MicroKernelException {
-        // create a private branch
+    public String merge(String branchRevisionId, String message) throws MicroKernelException
{
+        // merge a private branch with current head revision
 
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
 
-        Id revId = Id.fromString(privateRevisionId);
+        Id revId = Id.fromString(branchRevisionId);
 
         try {
-            CommitBuilder cb = rep.getCommitBuilder(revId, "");
-            return cb.doMerge().toString();
+            return rep.getCommitBuilder(revId, message).doMerge().toString();
         } catch (Exception e) {
             throw new MicroKernelException(e);
         }



Mime
View raw message