diff options
author | Ivan Frade <ifrade@google.com> | 2023-05-08 15:00:46 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2023-05-08 15:00:46 -0400 |
commit | 73f9f55e3b87a8fa9f9f5d40b6ace6a09fbbc16b (patch) | |
tree | fb9782f366412586d9db34c51f09b550d92f655e /org.eclipse.jgit | |
parent | 74fa245b3c3ccf13afcbec7911c7c8459e48527d (diff) | |
parent | ce88e62edc4dfd6e07d43720c399ec169d594ad7 (diff) | |
download | jgit-73f9f55e3b87a8fa9f9f5d40b6ace6a09fbbc16b.tar.gz jgit-73f9f55e3b87a8fa9f9f5d40b6ace6a09fbbc16b.zip |
Merge "PackWriter: write the PackReverseIndex file"
Diffstat (limited to 'org.eclipse.jgit')
4 files changed, 84 insertions, 3 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 66bcf73987..92e23b8b40 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 @@ -577,6 +577,7 @@ public class DfsGarbageCollector { cfg.setReuseObjects(true); cfg.setDeltaCompress(false); cfg.setBuildBitmaps(false); + cfg.setWriteReverseIndex(false); try (PackWriter pw = new PackWriter(cfg, ctx); RevWalk pool = new RevWalk(ctx)) { 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 bad572459a..666e9d8cbc 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 @@ -62,6 +62,7 @@ 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.lib.AnyObjectId; import org.eclipse.jgit.lib.AsyncObjectSizeQueue; import org.eclipse.jgit.lib.BatchingProgressMonitor; @@ -1137,6 +1138,38 @@ public class PackWriter implements AutoCloseable { } /** + * Whether the writer will write a reverse index file. The configuration + * flag must be on and the writer must be able to write corresponding + * forward index. + * + * @return whether the writer will write a reverse index file + */ + public boolean isReverseIndexEnabled() { + // Only write the reverse index if the writer is configured to and the + // forward index that it would correspond to will be written. + return config.isWriteReverseIndex() && !isIndexDisabled(); + } + + /** + * Write the pack's reverse index file to the output stream. + * + * @param stream + * where to write the file contents to + * @throws IOException + * if writing to the stream fails + */ + public void writeReverseIndex(OutputStream stream) throws IOException { + if (!isReverseIndexEnabled()) { + return; + } + long writeStart = System.currentTimeMillis(); + PackReverseIndexWriter writer = PackReverseIndexWriter + .createWriter(stream); + writer.write(sortByName(), packcsum); + stats.timeWriting += System.currentTimeMillis() - writeStart; + } + + /** * Create a bitmap index file to match the pack file just written. * <p> * Called after {@link #prepareBitmapIndex(ProgressMonitor)}. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java index c4b6bf955e..4c080f4761 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java @@ -745,6 +745,13 @@ public final class ConfigConstants { public static final String CONFIG_KEY_BITMAP_RECENT_COMMIT_COUNT = "bitmaprecentcommitspan"; /** + * The "pack.writeReverseIndex" key + * + * @since 6.6 + */ + public static final String CONFIG_KEY_WRITE_REVERSE_INDEX = "writeReverseIndex"; + + /** * The "pack.buildBitmaps" key * @since 5.8 */ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java index a0c978f6ea..8177425665 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java @@ -27,7 +27,10 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_DELTA_CACHE_SIZE; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_DELTA_COMPRESSION; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_DEPTH; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_INDEXVERSION; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_SIZE_PREVENT_RACYPACK; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PRESERVE_OLD_PACKS; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PRUNE_PRESERVED; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_REUSE_DELTAS; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_REUSE_OBJECTS; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_SEARCH_FOR_REUSE_TIMEOUT; @@ -36,10 +39,8 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_THREADS; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WAIT_PREVENT_RACYPACK; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WINDOW; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WINDOW_MEMORY; -import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX; +import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_WRITE_REVERSE_INDEX; import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION; -import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PRESERVE_OLD_PACKS; -import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_PRUNE_PRESERVED; import java.time.Duration; import java.util.concurrent.Executor; @@ -162,6 +163,14 @@ public class PackConfig { public static final int DEFAULT_INDEX_VERSION = 2; /** + * Default value of the write reverse index option: {@value} + * + * @see #setWriteReverseIndex(boolean) + * @since 6.6 + */ + public static final boolean DEFAULT_WRITE_REVERSE_INDEX = false; + + /** * Default value of the build bitmaps option: {@value} * * @see #setBuildBitmaps(boolean) @@ -292,6 +301,8 @@ public class PackConfig { private int indexVersion = DEFAULT_INDEX_VERSION; + private boolean writeReverseIndex = DEFAULT_WRITE_REVERSE_INDEX; + private boolean buildBitmaps = DEFAULT_BUILD_BITMAPS; private int bitmapContiguousCommitCount = DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT; @@ -373,6 +384,7 @@ public class PackConfig { this.threads = cfg.threads; this.executor = cfg.executor; this.indexVersion = cfg.indexVersion; + this.writeReverseIndex = cfg.writeReverseIndex; this.buildBitmaps = cfg.buildBitmaps; this.bitmapContiguousCommitCount = cfg.bitmapContiguousCommitCount; this.bitmapRecentCommitCount = cfg.bitmapRecentCommitCount; @@ -974,6 +986,31 @@ public class PackConfig { } /** + * True if the writer should write reverse index files. + * + * Default setting: {@value #DEFAULT_WRITE_REVERSE_INDEX} + * + * @return whether the writer should write reverse index files + * @since 6.6 + */ + public boolean isWriteReverseIndex() { + return writeReverseIndex; + } + + /** + * Set whether the writer will write reverse index files. + * + * Default setting: {@value #DEFAULT_WRITE_REVERSE_INDEX} + * + * @param writeReverseIndex + * whether the writer should write reverse index files + * @since 6.6 + */ + public void setWriteReverseIndex(boolean writeReverseIndex) { + this.writeReverseIndex = writeReverseIndex; + } + + /** * True if writer is allowed to build bitmaps for indexes. * * Default setting: {@value #DEFAULT_BUILD_BITMAPS} @@ -1286,6 +1323,8 @@ public class PackConfig { setSinglePack(rc.getBoolean(CONFIG_PACK_SECTION, CONFIG_KEY_SINGLE_PACK, getSinglePack())); + setWriteReverseIndex(rc.getBoolean(CONFIG_PACK_SECTION, + CONFIG_KEY_WRITE_REVERSE_INDEX, isWriteReverseIndex())); setBuildBitmaps(rc.getBoolean(CONFIG_PACK_SECTION, CONFIG_KEY_BUILD_BITMAPS, isBuildBitmaps())); setBitmapContiguousCommitCount(rc.getInt(CONFIG_PACK_SECTION, @@ -1347,6 +1386,7 @@ public class PackConfig { b.append(", reuseDeltas=").append(isReuseDeltas()); //$NON-NLS-1$ b.append(", reuseObjects=").append(isReuseObjects()); //$NON-NLS-1$ b.append(", deltaCompress=").append(isDeltaCompress()); //$NON-NLS-1$ + b.append(", writeReverseIndex=").append(isWriteReverseIndex()); // $NON-NLS-1$ b.append(", buildBitmaps=").append(isBuildBitmaps()); //$NON-NLS-1$ b.append(", bitmapContiguousCommitCount=") //$NON-NLS-1$ .append(getBitmapContiguousCommitCount()); |