}
private static MergedReftable merge(byte[]... table) {
- List<Reftable> stack = new ArrayList<>(table.length);
+ List<ReftableReader> stack = new ArrayList<>(table.length);
for (byte[] b : table) {
stack.add(read(b));
}
import java.util.Collections;
import java.util.List;
-import org.eclipse.jgit.internal.storage.reftable.Reftable;
+import org.eclipse.jgit.internal.storage.reftable.ReftableReader;
/**
* Tracks multiple open
- * {@link org.eclipse.jgit.internal.storage.reftable.Reftable} instances.
+ * {@link org.eclipse.jgit.internal.storage.reftable.ReftableReader} instances.
*/
public class DfsReftableStack implements AutoCloseable {
/**
}
private final List<DfsReftable> files;
- private final List<Reftable> tables;
+ private final List<ReftableReader> tables;
private DfsReftableStack(int tableCnt) {
this.files = new ArrayList<>(tableCnt);
* @return unmodifiable list of tables, in the same order the files were
* passed to {@link #open(DfsReader, List)}.
*/
- public List<Reftable> readers() {
+ public List<ReftableReader> readers() {
return Collections.unmodifiableList(tables);
}
/** {@inheritDoc} */
@Override
public void close() {
- for (Reftable t : tables) {
+ for (ReftableReader t : tables) {
try {
t.close();
} catch (IOException e) {
private boolean canCompactTopOfStack(ReftableConfig cfg)
throws IOException {
DfsReftableStack stack = refdb.stack();
- List<Reftable> readers = stack.readers();
+ List<ReftableReader> readers = stack.readers();
if (readers.isEmpty()) {
return false;
}
private ReftableWriter.Stats compactTopOfStack(OutputStream out,
ReftableConfig cfg, byte[] newTable) throws IOException {
- List<Reftable> stack = refdb.stack().readers();
- Reftable last = stack.get(stack.size() - 1);
+ List<ReftableReader> stack = refdb.stack().readers();
+ ReftableReader last = stack.get(stack.size() - 1);
- List<Reftable> tables = new ArrayList<>(2);
+ List<ReftableReader> tables = new ArrayList<>(2);
tables.add(last);
tables.add(new ReftableReader(BlockSource.from(newTable)));
* A {@code MergedReftable} is not thread-safe.
*/
public class MergedReftable extends Reftable {
- private final Reftable[] tables;
+ private final ReftableReader[] tables;
/**
* Initialize a merged table reader.
* <p>
- * The tables in {@code tableStack} will be closed when this
- * {@code MergedReftable} is closed.
*
* @param tableStack
* stack of tables to read from. The base of the stack is at
* {@code tableStack.size() - 1}. The top of the stack (higher
* index) shadows the base of the stack (lower index).
*/
- public MergedReftable(List<Reftable> tableStack) {
- tables = tableStack.toArray(new Reftable[0]);
+ public MergedReftable(List<ReftableReader> tableStack) {
+ tables = tableStack.toArray(new ReftableReader[0]);
// Tables must expose deletes to this instance to correctly
// shadow references from lower tables.
- for (Reftable t : tables) {
+ for (ReftableReader t : tables) {
t.setIncludeDeletes(true);
}
}
return m;
}
- /** {@inheritDoc} */
- @Override
- public void close() throws IOException {
- for (Reftable t : tables) {
- t.close();
- }
- }
-
int queueSize() {
return Math.max(1, tables.length);
}
/**
* Abstract table of references.
*/
-public abstract class Reftable implements AutoCloseable {
+public abstract class Reftable {
/**
* References to convert into a reftable
*
}
return new SymbolicRef(ref.getName(), dst, ref.getUpdateIndex());
}
-
- /** {@inheritDoc} */
- @Override
- public abstract void close() throws IOException;
}
*/
public class ReftableCompactor {
private final ReftableWriter writer;
- private final ArrayDeque<Reftable> tables = new ArrayDeque<>();
+ private final ArrayDeque<ReftableReader> tables = new ArrayDeque<>();
private long compactBytesLimit;
private long bytesToCompact;
* @throws java.io.IOException
* update indexes of a reader cannot be accessed.
*/
- public void addAll(List<? extends Reftable> readers) throws IOException {
- tables.addAll(readers);
- for (Reftable r : readers) {
- if (r instanceof ReftableReader) {
- adjustUpdateIndexes((ReftableReader) r);
- }
+ public void addAll(List<ReftableReader> readers) throws IOException {
+ for (ReftableReader r : readers) {
+ tables.add(r);
+ adjustUpdateIndexes(r);
}
}
* {@code ReftableReader} is not thread-safe. Concurrent readers need their own
* instance to read from the same file.
*/
-public class ReftableReader extends Reftable {
+public class ReftableReader extends Reftable implements AutoCloseable {
private final BlockSource src;
private int blockSize = -1;