diff options
author | Kevin Corcoran <kevin.corcoran@puppetlabs.com> | 2016-04-13 15:55:08 -0700 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2016-10-24 14:00:02 +0900 |
commit | fa0a93119cd3bc6e2673be25a89b8d7638598f3d (patch) | |
tree | dd6776c12f35a16c0d8c3ce672d2ac02f9a09cd3 | |
parent | 88f433be84e27468d9234b0305b97139d593c8a9 (diff) | |
download | jgit-fa0a93119cd3bc6e2673be25a89b8d7638598f3d.tar.gz jgit-fa0a93119cd3bc6e2673be25a89b8d7638598f3d.zip |
Make streamFileThreshold configurable
Previously, the streamFileThreshold, the threshold at which a file
would be streamed rather than loaded entirely into memory, was only
configurable on a global basis.
This commit makes this threshold configurable on a per-loader basis.
Bug: 490404
Change-Id: I492c18c3155dbf56eedda9044a61d76120fd75f9
Signed-off-by: Kevin Corcoran <kevin.corcoran@puppetlabs.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
4 files changed, 53 insertions, 8 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java index ba07d6842f..1c10bb335a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java @@ -310,6 +310,27 @@ public class PackFileTest extends LocalDiskRepositoryTestCase { } } + @Test + public void testConfigurableStreamFileThreshold() throws Exception { + byte[] data = getRng().nextBytes(300); + RevBlob id = tr.blob(data); + tr.branch("master").commit().add("A", id).create(); + tr.packAndPrune(); + assertTrue("has blob", wc.has(id)); + + ObjectLoader ol = wc.open(id); + ObjectStream in = ol.openStream(); + assertTrue(in instanceof ObjectStream.SmallStream); + assertEquals(300, in.available()); + in.close(); + + wc.setStreamFileThreshold(299); + ol = wc.open(id); + in = ol.openStream(); + assertTrue(in instanceof ObjectStream.Filter); + assertEquals(1, in.available()); + } + private static byte[] clone(int first, byte[] base) { byte[] r = new byte[base.length]; System.arraycopy(base, 1, r, 1, r.length - 1); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java index 2f61dea0d5..8c9329503f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java @@ -113,6 +113,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { DfsReader(DfsObjDatabase db) { this.db = db; + this.streamFileThreshold = db.getReaderOptions().getStreamFileThreshold(); } DfsReaderOptions getOptions() { @@ -125,10 +126,6 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { return baseCache; } - int getStreamFileThreshold() { - return getOptions().getStreamFileThreshold(); - } - @Override public ObjectReader newReader() { return new DfsReader(db); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java index a2c0561ae1..a742d1747e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java @@ -94,12 +94,14 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs { WindowCursor(FileObjectDatabase db) { this.db = db; this.createdFromInserter = null; + this.streamFileThreshold = WindowCache.getStreamFileThreshold(); } WindowCursor(FileObjectDatabase db, @Nullable ObjectDirectoryInserter createdFromInserter) { this.db = db; this.createdFromInserter = createdFromInserter; + this.streamFileThreshold = WindowCache.getStreamFileThreshold(); } DeltaBaseCache getDeltaBaseCache() { @@ -337,10 +339,6 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs { } } - int getStreamFileThreshold() { - return WindowCache.getStreamFileThreshold(); - } - @Override @Nullable public ObjectInserter getCreatedFromInserter() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index b23145d798..263fc99745 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -66,6 +66,12 @@ public abstract class ObjectReader implements AutoCloseable { public static final int OBJ_ANY = -1; /** + * The threshold at which a file will be streamed rather than + * loaded entirely into memory. + */ + protected int streamFileThreshold; + + /** * Construct a new reader from the same data. * <p> * Applications can use this method to build a new reader from the same data @@ -445,6 +451,29 @@ public abstract class ObjectReader implements AutoCloseable { public abstract void close(); /** + * Sets the threshold at which a file will be streamed rather than loaded + * entirely into memory + * + * @param threshold + * the new threshold + * @since 4.6 + */ + public void setStreamFileThreshold(int threshold) { + streamFileThreshold = threshold; + } + + /** + * Returns the threshold at which a file will be streamed rather than loaded + * entirely into memory + * + * @return the threshold in bytes + * @since 4.6 + */ + public int getStreamFileThreshold() { + return streamFileThreshold; + } + + /** * Wraps a delegate ObjectReader. * * @since 4.4 |