summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorChris Aniszczyk <caniszczyk@gmail.com>2012-03-05 23:44:44 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2012-03-05 23:44:45 -0500
commitdb29665e64f508eefa12ba8c3c692312f4c9a73e (patch)
treefafd9f95000c9f067abb99c7aa777bfeb76c9a21 /org.eclipse.jgit
parenteedd77a97b3eb5c404ac8464ea3a59498a121c72 (diff)
parent88fe2836edab8d8ce82d28acd9d07b061988ff3a (diff)
downloadjgit-db29665e64f508eefa12ba8c3c692312f4c9a73e.tar.gz
jgit-db29665e64f508eefa12ba8c3c692312f4c9a73e.zip
Merge "Quickfix for AutoCRLF handling"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java25
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java4
3 files changed, 27 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
index 0355e56f5f..e03fe35719 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java
@@ -109,6 +109,29 @@ public abstract class ObjectInserter {
return tempBuffer;
}
+ static private final int tempBufSize;
+ static {
+ String s = System.getProperty("jgit.tempbufmaxsize");
+ if (s != null)
+ tempBufSize = Integer.parseInt(s);
+ else
+ tempBufSize = 1000000;
+ }
+
+ /**
+ * @param hintSize
+ * @return a temporary byte array for use by the caller
+ */
+ protected byte[] buffer(long hintSize) {
+ if (hintSize >= tempBufSize)
+ tempBuffer = new byte[0];
+ else if (tempBuffer == null)
+ tempBuffer = new byte[(int) hintSize];
+ else if (tempBuffer.length < hintSize)
+ tempBuffer = new byte[(int) hintSize];
+ return tempBuffer;
+ }
+
/** @return digest to help compute an ObjectId */
protected MessageDigest digest() {
digest.reset();
@@ -172,7 +195,7 @@ public abstract class ObjectInserter {
md.update((byte) ' ');
md.update(Constants.encodeASCII(length));
md.update((byte) 0);
- byte[] buf = buffer();
+ byte[] buf = buffer(length);
while (length > 0) {
int n = in.read(buf, 0, (int) Math.min(length, buf.length));
if (n < 0)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java
index 335e284e2b..e80a324752 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsInserter.java
@@ -116,7 +116,7 @@ public class DfsInserter extends ObjectInserter {
@Override
public ObjectId insert(int type, long len, InputStream in)
throws IOException {
- byte[] buf = buffer();
+ byte[] buf = buffer(len);
if (len <= buf.length) {
IO.readFully(in, buf, 0, (int) len);
return insert(type, buf, 0, (int) len);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
index ffd5c4149f..75f6b0bdaa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectoryInserter.java
@@ -95,8 +95,8 @@ class ObjectDirectoryInserter extends ObjectInserter {
@Override
public ObjectId insert(final int type, long len, final InputStream is)
throws IOException {
- if (len <= buffer().length) {
- byte[] buf = buffer();
+ byte[] buf = buffer(len);
+ if (len <= buf.length) {
int actLen = IO.readFully(is, buf, 0);
return insert(type, buf, 0, actLen);