jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1091112 - in /jackrabbit/sandbox/microkernel/src/main/java/org: apache/jackrabbit/mk/store/ObjectStore.java apache/jackrabbit/mk/store/git/GitStore.java eclipse/jgit/storage/file/ObjectDbInserter.java
Date Mon, 11 Apr 2011 16:27:33 GMT
Author: stefan
Date: Mon Apr 11 16:27:32 2011
New Revision: 1091112

URL: http://svn.apache.org/viewvc?rev=1091112&view=rev
Log:
MicroKernel prototype (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/eclipse/jgit/storage/file/ObjectDbInserter.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java?rev=1091112&r1=1091111&r2=1091112&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/ObjectStore.java
Mon Apr 11 16:27:32 2011
@@ -70,4 +70,7 @@ public class ObjectStore implements Cons
         return getCommit(store.getHeadCommitId());
     }
 
+    public String computeId(int type, byte[] data) {
+        return store.computeId(type, data);
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java?rev=1091112&r1=1091111&r2=1091112&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/git/GitStore.java
Mon Apr 11 16:27:32 2011
@@ -75,6 +75,10 @@ public class GitStore implements DataSto
         RefUpdate.Result result = refUpd.update();
     }
 
+    public String computeId(int type, byte[] data) {
+        return rep.getObjectDb().newInserter().idFor(type, data).name();
+    }
+
     //------------------------------------------------------------< DataStore >
     public byte[] get(String id) throws Exception {
         return get(id, ANY);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/eclipse/jgit/storage/file/ObjectDbInserter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/eclipse/jgit/storage/file/ObjectDbInserter.java?rev=1091112&r1=1091111&r2=1091112&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/eclipse/jgit/storage/file/ObjectDbInserter.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/eclipse/jgit/storage/file/ObjectDbInserter.java
Mon Apr 11 16:27:32 2011
@@ -18,9 +18,13 @@ package org.eclipse.jgit.storage.file;
 
 import org.apache.jackrabbit.mk.store.Constants;
 import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.ObjectId;
 
+import java.io.EOFException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
+import java.security.MessageDigest;
 
 /**
  *
@@ -38,4 +42,34 @@ public class ObjectDbInserter extends Ob
         out.write(Long.toString(len).getBytes());
         out.write((byte) 0);
     }
+
+    @Override
+    public ObjectId idFor(int objectType, long length, InputStream in) throws IOException
{
+        MessageDigest md = digest();
+        md.update(Constants.TYPE_NAMES[objectType].getBytes());
+        md.update((byte) ' ');
+        md.update(Long.toString(length).getBytes());
+        md.update((byte) 0);
+        byte[] buf = buffer();
+        while (length > 0) {
+                int n = in.read(buf, 0, (int) Math.min(length, buf.length));
+                if (n < 0)
+                        throw new EOFException("Unexpected end of input");
+                md.update(buf, 0, n);
+                length -= n;
+        }
+        return ObjectId.fromRaw(md.digest());
+    }
+
+    @Override
+    public ObjectId idFor(int type, byte[] data, int off, int len) {
+        MessageDigest md = digest();
+        md.update(Constants.TYPE_NAMES[type].getBytes());
+        md.update((byte) ' ');
+        md.update(Long.toString(len).getBytes());
+        md.update((byte) 0);
+        md.update(data, off, len);
+        return ObjectId.fromRaw(md.digest());
+    }
+
 }



Mime
View raw message