diff options
author | Ronald Bhuleskar <funronald@google.com> | 2023-05-17 16:29:14 -0700 |
---|---|---|
committer | Jonathan Tan <jonathantanmy@google.com> | 2023-07-18 14:21:48 -0700 |
commit | 3b77e33ad8f8206ff30a66ea2d15c3e1f1b731b2 (patch) | |
tree | b34dcd1c3b4b91d9bc8df19410368b62a7d920e9 /org.eclipse.jgit | |
parent | 77aec62141cd22067f853eb0e0f7a2df757e3155 (diff) | |
download | jgit-3b77e33ad8f8206ff30a66ea2d15c3e1f1b731b2.tar.gz jgit-3b77e33ad8f8206ff30a66ea2d15c3e1f1b731b2.zip |
CommitGraphWriter: add option for writing/using bloom filters
Currently, bloom filters are written and used without any way to turn
them off. Add a per-repo config variable to control whether bloom
filters are written. As for reading, add a JGit option to control this.
(A JGit option is used instead of a per-repo config variable as there is
usually no reason not to use the bloom filters if they are present, but
a global control to disable them is useful if there turns out to be an
issue with the implementation of bloom filters.)
The config that controls reading is the same as C Git, but the config
for writing is not: C Git has no config to control writing, but whether
bloom filters are written depends on whether bloom filters are already
present and what arguments are passed to "git commit-graph write". See
the manpage of "git commit-graph" for more information.
Change-Id: I1b7b25340387673506252b9260b22bfe147bde58
Diffstat (limited to 'org.eclipse.jgit')
6 files changed, 102 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphLoader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphLoader.java index d6310e0a85..867d522e08 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphLoader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphLoader.java @@ -27,9 +27,12 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.NB; +import org.eclipse.jgit.util.SystemReader; import org.eclipse.jgit.util.io.SilentFileInputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,6 +142,17 @@ public class CommitGraphLoader { chunks.add(new ChunkSegment(id, offset)); } + boolean readChangedPathFilters; + try { + readChangedPathFilters = SystemReader.getInstance() + .getJGitConfig() + .getBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION, + ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, false); + } catch (ConfigInvalidException e) { + // Use the default value if, for some reason, the config couldn't be read. + readChangedPathFilters = false; + } + CommitGraphBuilder builder = CommitGraphBuilder.builder(); for (int i = 0; i < numberOfChunks; i++) { long chunkOffset = chunks.get(i).offset; @@ -167,10 +181,14 @@ public class CommitGraphLoader { builder.addExtraList(buffer); break; case CHUNK_ID_BLOOM_FILTER_INDEX: - builder.addBloomFilterIndex(buffer); + if (readChangedPathFilters) { + builder.addBloomFilterIndex(buffer); + } break; case CHUNK_ID_BLOOM_FILTER_DATA: - builder.addBloomFilterData(buffer); + if (readChangedPathFilters) { + builder.addBloomFilterData(buffer); + } break; default: LOG.warn(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java index eb9dfb4d9c..9d1c33959f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java @@ -73,6 +73,8 @@ public class CommitGraphWriter { private final GraphCommits graphCommits; + private final boolean generateChangedPathFilters; + /** * Create commit-graph writer for these commits. * @@ -80,8 +82,22 @@ public class CommitGraphWriter { * the commits which will be writen to the commit-graph. */ public CommitGraphWriter(@NonNull GraphCommits graphCommits) { + this(graphCommits, false); + } + + /** + * Create commit-graph writer for these commits. + * + * @param graphCommits + * the commits which will be writen to the commit-graph. + * @param generateChangedPathFilters + * whether changed path filters are generated + */ + public CommitGraphWriter(@NonNull GraphCommits graphCommits, + boolean generateChangedPathFilters) { this.graphCommits = graphCommits; this.hashsz = OBJECT_ID_LENGTH; + this.generateChangedPathFilters = generateChangedPathFilters; } /** @@ -140,11 +156,14 @@ public class CommitGraphWriter { chunks.add(new ChunkHeader(CHUNK_ID_EXTRA_EDGE_LIST, graphCommits.getExtraEdgeCnt() * 4)); } - BloomFilterChunks bloomFilterChunks = computeBloomFilterChunks(stats); - chunks.add(new ChunkHeader(CHUNK_ID_BLOOM_FILTER_INDEX, - bloomFilterChunks.index)); - chunks.add(new ChunkHeader(CHUNK_ID_BLOOM_FILTER_DATA, - bloomFilterChunks.data)); + if (generateChangedPathFilters) { + BloomFilterChunks bloomFilterChunks = computeBloomFilterChunks( + stats); + chunks.add(new ChunkHeader(CHUNK_ID_BLOOM_FILTER_INDEX, + bloomFilterChunks.index)); + chunks.add(new ChunkHeader(CHUNK_ID_BLOOM_FILTER_DATA, + bloomFilterChunks.data)); + } return chunks; } 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 9f415782fa..8cb94dcf4b 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 @@ -81,6 +81,8 @@ public class DfsGarbageCollector { private ReftableConfig reftableConfig; private boolean convertToReftable = true; private boolean writeCommitGraph; + + private boolean writeBloomFilter; private boolean includeDeletes; private long reftableInitialMinUpdateIndex = 1; private long reftableInitialMaxUpdateIndex = 1; @@ -299,6 +301,20 @@ public class DfsGarbageCollector { } /** + * Toggle bloom filter generation. + * <p> + * False by default. + * + * @param enable + * Whether bloom filter generation is enabled + * @return {@code this} + */ + public DfsGarbageCollector setWriteBloomFilter(boolean enable) { + writeBloomFilter = enable; + return this; + } + + /** * Create a single new pack file containing all of the live objects. * <p> * This method safely decides which packs can be expired after the new pack @@ -774,7 +790,8 @@ public class DfsGarbageCollector { RevWalk pool = new RevWalk(ctx)) { GraphCommits gcs = GraphCommits.fromWalk(pm, allTips, pool); CountingOutputStream cnt = new CountingOutputStream(out); - CommitGraphWriter writer = new CommitGraphWriter(gcs); + CommitGraphWriter writer = new CommitGraphWriter(gcs, + writeBloomFilter); writer.write(pm, cnt); pack.addFileExt(COMMIT_GRAPH); pack.setFileSize(COMMIT_GRAPH, cnt.getCount()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java index 44429a7786..5172963e2e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java @@ -108,7 +108,8 @@ public class FileCommitGraph { // commit-graph file was not modified return this; } - return new GraphSnapshot(file, FileSnapshot.save(file), open(file)); + return new GraphSnapshot(file, FileSnapshot.save(file), + open(file)); } private static CommitGraph open(File file) { 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 ace0d7be7b..144ff4aa04 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 @@ -135,6 +135,8 @@ public class GC { private static final int DEFAULT_AUTOLIMIT = 6700; + private static final boolean DEFAULT_WRITE_BLOOM_FILTER = false; + private static final boolean DEFAULT_WRITE_COMMIT_GRAPH = false; private static volatile ExecutorService executor; @@ -959,7 +961,8 @@ public class GC { File tmpFile = null; try (RevWalk walk = new RevWalk(repo)) { CommitGraphWriter writer = new CommitGraphWriter( - GraphCommits.fromWalk(pm, wants, walk)); + GraphCommits.fromWalk(pm, wants, walk), + shouldWriteBloomFilter()); tmpFile = File.createTempFile("commit_", //$NON-NLS-1$ COMMIT_GRAPH.getTmpExtension(), repo.getObjectDatabase().getInfoDirectory()); @@ -1011,7 +1014,7 @@ public class GC { /** * If {@code true}, will rewrite the commit-graph file when gc is run. * - * @return true if commit-graph should be writen. Default is {@code false}. + * @return true if commit-graph should be written. Default is {@code false}. */ boolean shouldWriteCommitGraphWhenGc() { return repo.getConfig().getBoolean(ConfigConstants.CONFIG_GC_SECTION, @@ -1019,6 +1022,17 @@ public class GC { DEFAULT_WRITE_COMMIT_GRAPH); } + /** + * If {@code true}, generates bloom filter in the commit-graph file. + * + * @return true if bloom filter should be written. Default is {@code false}. + */ + boolean shouldWriteBloomFilter() { + return repo.getConfig().getBoolean(ConfigConstants.CONFIG_GC_SECTION, + ConfigConstants.CONFIG_KEY_WRITE_CHANGED_PATHS, + DEFAULT_WRITE_BLOOM_FILTER); + } + private static boolean isHead(Ref ref) { return ref.getName().startsWith(Constants.R_HEADS); } 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 621db89f66..7776b00625 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java @@ -109,6 +109,7 @@ public final class ConfigConstants { /** * The "fetch" section + * * @since 3.3 */ public static final String CONFIG_FETCH_SECTION = "fetch"; @@ -947,4 +948,25 @@ public final class ConfigConstants { * @since 5.13.2 */ public static final String CONFIG_KEY_PRUNE_PRESERVED = "prunepreserved"; + + /** + * The "commitGraph" section + * + * @since 6.7 + */ + public static final String CONFIG_COMMIT_GRAPH_SECTION = "commitGraph"; + + /** + * The "writeChangedPaths" key + * + * @since 6.7 + */ + public static final String CONFIG_KEY_WRITE_CHANGED_PATHS = "writeChangedPaths"; + + /** + * The "readChangedPaths" key + * + * @since 6.7 + */ + public static final String CONFIG_KEY_READ_CHANGED_PATHS = "readChangedPaths"; } |