summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2014-08-12 14:57:28 -0700
committerShawn Pearce <spearce@spearce.org>2014-08-12 18:55:12 -0700
commit63eb9042a4b7e71c4ff0bbea7005cf453c2b9df9 (patch)
treee7693c2d9244b23536802cfd98956f898aa65f1c /org.eclipse.jgit/src/org/eclipse
parentfa5582f3fea490e56b5d7ef97501968e57d8ee64 (diff)
downloadjgit-63eb9042a4b7e71c4ff0bbea7005cf453c2b9df9.tar.gz
jgit-63eb9042a4b7e71c4ff0bbea7005cf453c2b9df9.zip
DfsInserter: buffer up to streamFileThreshold from InputStream
Since 2badedcbe0f87c0a in-core merges can write up to 10 MiB into a TemporaryBuffer.Heap strategy, where the data is stored as a chain of byte[] blocks. Support the inserter reading up to the streamFileThreshold (default 50 MiB) from the supplied input stream and hash the content to determine if the merged result blob is already present in the repository. This allows the inserter to avoid creating duplicate objects in more cases, reducing repository pack file churn. Change-Id: I38967e2a0cff14c0a856cdb46a2c8fedbeb21ed5
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
index 76554c0ad8..6be6509b46 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
@@ -119,7 +119,7 @@ public class DfsInserter extends ObjectInserter {
@Override
public ObjectId insert(int type, long len, InputStream in)
throws IOException {
- byte[] buf = buffer();
+ byte[] buf = insertBuffer(len);
if (len <= buf.length) {
IO.readFully(in, buf, 0, (int) len);
return insert(type, buf, 0, (int) len);
@@ -144,6 +144,20 @@ public class DfsInserter extends ObjectInserter {
return endObject(ObjectId.fromRaw(md.digest()), offset);
}
+ private byte[] insertBuffer(long len) {
+ byte[] buf = buffer();
+ if (len <= buf.length)
+ return buf;
+ if (len < db.getReaderOptions().getStreamFileThreshold()) {
+ try {
+ return new byte[(int) len];
+ } catch (OutOfMemoryError noMem) {
+ return buf;
+ }
+ }
+ return buf;
+ }
+
@Override
public void flush() throws IOException {
if (packDsc == null)