From 1513a5632dcaf8c6e2d6998427087e11ba35566d Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 19 May 2017 13:47:10 -0700 Subject: [PATCH] Allow DfsReader to be subclassed Necessary if a DFS implementation wants to override close() to record DfsReaderIoStats. Change-Id: I144575f9bf1abf2c1fd72030550c4f0795fcf44d --- .../storage/dfs/DfsGarbageCollectorTest.java | 2 +- .../jgit/internal/storage/dfs/DfsInserter.java | 4 ++-- .../jgit/internal/storage/dfs/DfsObjDatabase.java | 2 +- .../eclipse/jgit/internal/storage/dfs/DfsReader.java | 12 +++++++++--- .../internal/storage/dfs/LargePackedWholeObject.java | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java index 32002fd01..17c1835bd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java @@ -674,7 +674,7 @@ public class DfsGarbageCollectorTest { private boolean isObjectInPack(AnyObjectId id, DfsPackFile pack) throws IOException { - try (DfsReader reader = new DfsReader(odb)) { + try (DfsReader reader = odb.newReader()) { return pack.hasObject(reader, id); } } 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 fd72756e3..e65c9fda7 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 @@ -530,7 +530,7 @@ public class DfsInserter extends ObjectInserter { } private class Reader extends ObjectReader { - private final DfsReader ctx = new DfsReader(db); + private final DfsReader ctx = db.newReader(); @Override public ObjectReader newReader() { @@ -647,7 +647,7 @@ public class DfsInserter extends ObjectInserter { @Override public ObjectStream openStream() throws IOException { - final DfsReader ctx = new DfsReader(db); + final DfsReader ctx = db.newReader(); if (srcPack != packKey) { try { // Post DfsInserter.flush() use the normal code path. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java index b1cb72dec..32ee6c288 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java @@ -170,7 +170,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase { } @Override - public ObjectReader newReader() { + public DfsReader newReader() { return new DfsReader(this); } 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 d4e7e86cc..d611469af 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 @@ -95,7 +95,7 @@ import org.eclipse.jgit.util.BlockList; * See the base {@link ObjectReader} documentation for details. Notably, a * reader is not thread safe. */ -public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { +public class DfsReader extends ObjectReader implements ObjectReuseAsIs { private static final int MAX_RESOLVE_MATCHES = 256; /** Temporary buffer large enough for at least one raw object id. */ @@ -112,7 +112,13 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { private DfsPackFile last; private boolean avoidUnreachable; - DfsReader(DfsObjDatabase db) { + /** + * Initialize a new DfsReader + * + * @param db + * parent DfsObjDatabase. + */ + protected DfsReader(DfsObjDatabase db) { this.db = db; this.streamFileThreshold = db.getReaderOptions().getStreamFileThreshold(); } @@ -129,7 +135,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs { @Override public ObjectReader newReader() { - return new DfsReader(db); + return db.newReader(); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java index 6d40a7505..73a93e657 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java @@ -99,7 +99,7 @@ final class LargePackedWholeObject extends ObjectLoader { @Override public ObjectStream openStream() throws MissingObjectException, IOException { - DfsReader ctx = new DfsReader(db); + DfsReader ctx = db.newReader(); InputStream in; try { in = new PackInputStream(pack, objectOffset + headerLength, ctx);