git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: Shawn Pearce <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: [EGIT PATCH] Convert author and comment on demand.
Date: Sun, 3 Dec 2006 01:45:09 +0100	[thread overview]
Message-ID: <200612030145.09576.robin.rosenberg@dewire.com> (raw)

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


             reply	other threads:[~2006-12-03  0:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-03  0:45 Robin Rosenberg [this message]
2006-12-03  2:16 ` [EGIT PATCH] Convert author and comment on demand Shawn Pearce
2006-12-03 12:18   ` Robin Rosenberg
2006-12-03 12:34     ` Jakub Narebski
2006-12-03 18:08       ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200612030145.09576.robin.rosenberg@dewire.com \
    --to=robin.rosenberg@dewire.com \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).