summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorSam Delmerico <delmerico@google.com>2024-03-04 17:40:37 -0800
committerSam Delmerico <delmerico@google.com>2024-03-29 06:43:28 -0700
commit82b224c0d109d4debe765f7c2ee5f220694eca58 (patch)
tree3ad164a93085ca1980a060a2e2aaa86b2d1f6496 /org.eclipse.jgit
parenta5ec41bd2822c5d926d4f75454b784917efb7941 (diff)
downloadjgit-82b224c0d109d4debe765f7c2ee5f220694eca58.tar.gz
jgit-82b224c0d109d4debe765f7c2ee5f220694eca58.zip
PackWriter: writeBitmapIndex takes bitmap index writer
PackWriter.writeBitmapIndex now takes an interface which will perform the writing of the bitmap index to an arbitrary backing storage. Change-Id: Icba89321d56f7b652bbcbfcd5ed3ec74999cb8c4
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java28
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackBitmapIndexWriter.java33
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java22
6 files changed, 76 insertions, 22 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
index 62b55d4734..a177669788 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
@@ -17,7 +17,6 @@ import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.IN
import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.RECEIVE;
import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE;
import static org.eclipse.jgit.internal.storage.dfs.DfsPackCompactor.configureReftable;
-import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.COMMIT_GRAPH;
import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
import static org.eclipse.jgit.internal.storage.pack.PackExt.OBJECT_SIZE_INDEX;
@@ -709,13 +708,7 @@ public class DfsGarbageCollector {
}
if (pw.prepareBitmapIndex(pm)) {
- try (DfsOutputStream out = objdb.writeFile(pack, BITMAP_INDEX)) {
- CountingOutputStream cnt = new CountingOutputStream(out);
- pw.writeBitmapIndex(cnt);
- pack.addFileExt(BITMAP_INDEX);
- pack.setFileSize(BITMAP_INDEX, cnt.getCount());
- pack.setBlockSize(BITMAP_INDEX, out.blockSize());
- }
+ pw.writeBitmapIndex(objdb.getPackBitmapIndexWriter(pack));
}
PackStatistics stats = pw.getStatistics();
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 9f6eb10256..616563ffdd 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
@@ -11,6 +11,7 @@
package org.eclipse.jgit.internal.storage.dfs;
import static java.util.stream.Collectors.joining;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -26,11 +27,14 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
+import org.eclipse.jgit.internal.storage.file.PackBitmapIndexWriterV1;
+import org.eclipse.jgit.internal.storage.pack.PackBitmapIndexWriter;
import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.util.io.CountingOutputStream;
/**
* Manages objects stored in
@@ -743,4 +747,28 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
dirty = true;
}
}
+
+ /**
+ * Returns a writer to store the bitmap index in this object database.
+ *
+ * @param pack
+ * Pack file to which the bitmaps are associated.
+ * @return a writer to store bitmaps associated with the pack
+ * @throws IOException
+ * when some I/O problem occurs while creating or writing to
+ * output stream
+ */
+ public PackBitmapIndexWriter getPackBitmapIndexWriter(
+ DfsPackDescription pack) throws IOException {
+ return (bitmaps, packDataChecksum) -> {
+ try (DfsOutputStream out = writeFile(pack, BITMAP_INDEX)) {
+ CountingOutputStream cnt = new CountingOutputStream(out);
+ PackBitmapIndexWriterV1 iw = new PackBitmapIndexWriterV1(cnt);
+ iw.write(bitmaps, packDataChecksum);
+ pack.addFileExt(BITMAP_INDEX);
+ pack.setFileSize(BITMAP_INDEX, cnt.getCount());
+ pack.setBlockSize(BITMAP_INDEX, out.blockSize());
+ }
+ };
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index fc058abcca..4c996730e8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -1399,7 +1399,7 @@ public class GC {
FileChannel idxChannel = fos.getChannel();
OutputStream idxStream = Channels
.newOutputStream(idxChannel)) {
- pw.writeBitmapIndex(idxStream);
+ pw.writeBitmapIndex(new PackBitmapIndexWriterV1(idxStream));
idxChannel.force(true);
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java
index a5c8423dfd..84326d5e62 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java
@@ -19,6 +19,7 @@ import java.text.MessageFormat;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder.StoredEntry;
+import org.eclipse.jgit.internal.storage.pack.PackBitmapIndexWriter;
import org.eclipse.jgit.lib.Constants;
import com.googlecode.javaewah.EWAHCompressedBitmap;
@@ -28,7 +29,7 @@ import com.googlecode.javaewah.EWAHCompressedBitmap;
*
* @see PackBitmapIndexV1
*/
-public class PackBitmapIndexWriterV1 {
+public class PackBitmapIndexWriterV1 implements PackBitmapIndexWriter {
private final DigestOutputStream out;
private final DataOutput dataOutput;
@@ -60,6 +61,7 @@ public class PackBitmapIndexWriterV1 {
* an error occurred while writing to the output stream, or this
* index format cannot store the object data supplied.
*/
+ @Override
public void write(PackBitmapIndexBuilder bitmaps, byte[] packDataChecksum)
throws IOException {
if (bitmaps == null || packDataChecksum.length != 20)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackBitmapIndexWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackBitmapIndexWriter.java
new file mode 100644
index 0000000000..9cf8c7f2b5
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackBitmapIndexWriter.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2024, Google Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.internal.storage.pack;
+
+import java.io.IOException;
+
+import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder;
+
+/**
+ * Represents a function that accepts a collection of bitmaps and write them
+ * into storage.
+ */
+@FunctionalInterface
+public interface PackBitmapIndexWriter {
+ /**
+ * @param bitmaps
+ * list of bitmaps to be written to a bitmap index
+ * @param packChecksum
+ * checksum of the pack that the bitmap index refers to
+ * @throws IOException
+ * thrown in case of IO errors while writing the bitmap index
+ */
+ public void write(PackBitmapIndexBuilder bitmaps, byte[] packChecksum)
+ throws IOException;
+} \ No newline at end of file
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
index 9e95231253..4350f97915 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
@@ -58,11 +58,10 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.SearchForReuseTimeout;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.internal.JGitText;
-import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder;
-import org.eclipse.jgit.internal.storage.file.PackBitmapIndexWriterV1;
import org.eclipse.jgit.internal.storage.file.PackIndexWriter;
import org.eclipse.jgit.internal.storage.file.PackObjectSizeIndexWriter;
import org.eclipse.jgit.internal.storage.file.PackReverseIndexWriter;
+import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.AsyncObjectSizeQueue;
import org.eclipse.jgit.lib.BatchingProgressMonitor;
@@ -121,7 +120,7 @@ import org.eclipse.jgit.util.TemporaryBuffer;
* pack is being stored as a file the matching index can be written out after
* writing the pack by {@link #writeIndex(OutputStream)}. An optional bitmap
* index can be made by calling {@link #prepareBitmapIndex(ProgressMonitor)}
- * followed by {@link #writeBitmapIndex(OutputStream)}.
+ * followed by {@link #writeBitmapIndex(PackBitmapIndexWriter)}.
* </p>
* <p>
* Class provide set of configurable options and
@@ -1130,7 +1129,7 @@ public class PackWriter implements AutoCloseable {
* Called after
* {@link #writePack(ProgressMonitor, ProgressMonitor, OutputStream)} that
* populates the list of objects to pack and before
- * {@link #writeBitmapIndex(OutputStream)} that destroys it.
+ * {@link #writeBitmapIndex(PackBitmapIndexWriter)} that destroys it.
* <p>
* Writing this index is only required for local pack storage. Packs sent on
* the network do not need to create an object size index.
@@ -1204,20 +1203,18 @@ public class PackWriter implements AutoCloseable {
* <p>
* Called after {@link #prepareBitmapIndex(ProgressMonitor)}.
*
- * @param bitmapIndexStream
- * output for the bitmap index data. Caller is responsible for
- * closing this stream.
+ * @param bitmapIndexWriter
+ * a writer to store the bitmap index in this object database
* @throws java.io.IOException
- * the index data could not be written to the supplied stream.
+ * the index data could not be written using the supplied writer
*/
- public void writeBitmapIndex(OutputStream bitmapIndexStream)
+ public void writeBitmapIndex(PackBitmapIndexWriter bitmapIndexWriter)
throws IOException {
if (writeBitmaps == null)
throw new IOException(JGitText.get().bitmapsMustBePrepared);
long writeStart = System.currentTimeMillis();
- final PackBitmapIndexWriterV1 iw = new PackBitmapIndexWriterV1(bitmapIndexStream);
- iw.write(writeBitmaps, packcsum);
+ bitmapIndexWriter.write(writeBitmaps, packcsum);
stats.timeWriting += System.currentTimeMillis() - writeStart;
}
@@ -2468,7 +2465,8 @@ public class PackWriter implements AutoCloseable {
* <p>
* To reduce memory internal state is cleared during this method, rendering
* the PackWriter instance useless for anything further than a call to write
- * out the new bitmaps with {@link #writeBitmapIndex(OutputStream)}.
+ * out the new bitmaps with
+ * {@link #writeBitmapIndex(PackBitmapIndexWriter)}.
*
* @param pm
* progress monitor to report bitmap building work.