This sppeds up reading commits a lot by only store the byte
array data when reading commits. For the eclipse plugin I only
need the tree to filter out which commits to display and I can
take the cost of converting the comments to string for the
very few commits to display. Only the displayed commits are actually
converted so this results in convertig author and comment information
for about five commits rather than 20,000 (in my repo).
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../src/org/spearce/jgit/lib/Commit.java | 73 +++++++++++++------
1 files changed, 50 insertions(+), 23 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Commit.java
b/org.spearce.jgit/src/org/spearce/jgit/lib/Commit.java
index 4e03a5a..14fa602 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Commit.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Commit.java
@@ -16,10 +16,16 @@
*/
package org.spearce.jgit.lib;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.spearce.jgit.errors.CorruptObjectException;
import org.spearce.jgit.errors.MissingObjectException;
public class Commit implements Treeish {
@@ -39,6 +45,8 @@ public class Commit implements Treeish {
private Tree treeObj;
+ private byte[] raw;
+
public Commit(final Repository db) {
objdb = db;
parentIds = new ArrayList(2);
@@ -58,29 +66,7 @@ public class Commit implements Treeish {
rawPtr += 48;
}
- //
- // if (n == null || !n.startsWith("author ")) {
- // throw new CorruptObjectException(commitId, "no author");
- // }
- // author = new PersonIdent(n.substring("author ".length()));
- //
- // n = br.readLine();
- // if (n == null || !n.startsWith("committer ")) {
- // throw new CorruptObjectException(commitId, "no committer");
- // }
- // committer = new PersonIdent(n.substring("committer ".length()));
- //
- // n = br.readLine();
- // if (n == null || !n.equals("")) {
- // throw new CorruptObjectException(commitId, "malformed header");
- // }
- //
- // tempMessage = new StringBuffer();
- // readBuf = new char[128];
- // while ((readLen = br.read(readBuf)) > 0) {
- // tempMessage.append(readBuf, 0, readLen);
- // }
- // message = tempMessage.toString();
+ this.raw = raw;
}
public ObjectId getCommitId() {
@@ -119,6 +105,7 @@ public class Commit implements Treeish {
}
public PersonIdent getAuthor() {
+ decode();
return author;
}
@@ -127,6 +114,7 @@ public class Commit implements Treeish {
}
public PersonIdent getCommitter() {
+ decode();
return committer;
}
@@ -139,9 +127,48 @@ public class Commit implements Treeish {
}
public String getMessage() {
+ decode();
return message;
}
+ private void decode() {
+ if (raw!=null) {
+ try {
+ BufferedReader br=new BufferedReader(new InputStreamReader(new
ByteArrayInputStream(raw)));
+ String n=br.readLine();
+ if (n == null || !n.startsWith("tree ")) {
+ throw new CorruptObjectException(commitId, "no tree");
+ }
+ while ((n = br.readLine())!=null && n.startsWith("parent "))
+ ;
+ if (n == null || !n.startsWith("author ")) {
+ throw new CorruptObjectException(commitId, "no author");
+ }
+ author = new PersonIdent(n.substring("author ".length()));
+ n = br.readLine();
+ if (n == null || !n.startsWith("committer ")) {
+ throw new CorruptObjectException(commitId, "no
committer");
+ }
+ committer = new
PersonIdent(n.substring("committer ".length()));
+ n = br.readLine();
+ if (n == null || !n.equals("")) {
+ throw new CorruptObjectException(commitId, "malformed
header");
+ }
+ StringBuffer tempMessage = new StringBuffer();
+ char[] readBuf = new char[2048];
+ int readLen;
+ while ((readLen = br.read(readBuf)) > 0) {
+ tempMessage.append(readBuf, 0, readLen);
+ }
+ message = tempMessage.toString();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ raw = null;
+ }
+ }
+ }
+
public void setMessage(final String m) {
message = m;
}
--
1.4.4.gf05d