summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackOutputStream.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java34
4 files changed, 46 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java
index 4d6dab4bb6..2f04751a1d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java
@@ -227,7 +227,7 @@ public class ObjectId extends AnyObjectId implements Serializable {
* the string to read from. Must be 40 characters long.
* @return the converted object id.
*/
- public static final ObjectId fromString(final String str) {
+ public static ObjectId fromString(final String str) {
if (str.length() != Constants.OBJECT_ID_STRING_LENGTH)
throw new IllegalArgumentException("Invalid id: " + str);
return fromHexString(Constants.encodeASCII(str), 0);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java
index d8df339d5e..91e50ad9d1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryPackParser.java
@@ -202,6 +202,11 @@ public class ObjectDirectoryPackParser extends PackParser {
}
@Override
+ protected void onPackHeader(long objectCount) throws IOException {
+ // Ignored, the count is not required.
+ }
+
+ @Override
protected void onBeginWholeObject(long streamPosition, int type,
long inflatedSize) throws IOException {
crc.reset();
@@ -232,6 +237,12 @@ public class ObjectDirectoryPackParser extends PackParser {
}
@Override
+ protected void onInflatedObjectData(PackedObjectInfo obj, int typeCode,
+ byte[] data) throws IOException {
+ // ObjectDirectory ignores this event.
+ }
+
+ @Override
protected void onObjectHeader(Source src, byte[] raw, int pos, int len)
throws IOException {
crc.update(raw, pos, len);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackOutputStream.java
index a7925b52b7..d9002e70b0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackOutputStream.java
@@ -231,7 +231,7 @@ public final class PackOutputStream extends OutputStream {
}
/** @return total number of bytes written since stream start. */
- long length() {
+ public long length() {
return count;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
index f5e763bde9..6f0c6c3b36 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
@@ -580,6 +580,7 @@ public abstract class PackParser {
PackedObjectInfo oe;
oe = newInfo(tempObjectId, visit.delta, visit.parent.id);
oe.setOffset(visit.delta.position);
+ onInflatedObjectData(oe, type, visit.data);
addObjectAndTrack(oe);
visit.id = oe;
@@ -768,6 +769,8 @@ public abstract class PackParser {
JGitText.get().unsupportedPackVersion, vers));
objectCount = NB.decodeUInt32(buf, p + 8);
use(hdrln);
+
+ onPackHeader(objectCount);
}
private void readPackFooter() throws IOException {
@@ -875,6 +878,7 @@ public abstract class PackParser {
objectDigest.update(Constants.encodeASCII(sz));
objectDigest.update((byte) 0);
+ final byte[] data;
boolean checkContentLater = false;
if (type == Constants.OBJ_BLOB) {
byte[] readBuffer = buffer();
@@ -891,9 +895,10 @@ public abstract class PackParser {
tempObjectId.fromRaw(objectDigest.digest(), 0);
checkContentLater = isCheckObjectCollisions()
&& readCurs.has(tempObjectId);
+ data = null;
} else {
- final byte[] data = inflateAndReturn(Source.INPUT, sz);
+ data = inflateAndReturn(Source.INPUT, sz);
objectDigest.update(data);
tempObjectId.fromRaw(objectDigest.digest(), 0);
verifySafeObject(tempObjectId, type, data);
@@ -902,6 +907,8 @@ public abstract class PackParser {
PackedObjectInfo obj = newInfo(tempObjectId, null, null);
obj.setOffset(pos);
onEndWholeObject(obj);
+ if (data != null)
+ onInflatedObjectData(obj, type, data);
addObjectAndTrack(obj);
if (checkContentLater)
deferredCheckBlobs.add(obj);
@@ -1144,6 +1151,31 @@ public abstract class PackParser {
int len) throws IOException;
/**
+ * Invoked for commits, trees, tags, and small blobs.
+ *
+ * @param obj
+ * the object info, populated.
+ * @param typeCode
+ * the type of the object.
+ * @param data
+ * inflated data for the object.
+ * @throws IOException
+ * the object cannot be archived.
+ */
+ protected abstract void onInflatedObjectData(PackedObjectInfo obj,
+ int typeCode, byte[] data) throws IOException;
+
+ /**
+ * Provide the implementation with the original stream's pack header.
+ *
+ * @param objCnt
+ * number of objects expected in the stream.
+ * @throws IOException
+ * the implementation refuses to work with this many objects.
+ */
+ protected abstract void onPackHeader(long objCnt) throws IOException;
+
+ /**
* Provide the implementation with the original stream's pack footer.
*
* @param hash