diff options
4 files changed, 57 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java index b4ebdcdf8e..ddc4a9d0ba 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java @@ -237,6 +237,26 @@ public class ObjectDirectoryTest extends RepositoryTestCase { } @Test + public void testWindowCursorGetCommitGraph() throws Exception { + db.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_COMMIT_GRAPH, true); + db.getConfig().setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, + ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, true); + + WindowCursor curs = new WindowCursor(db.getObjectDatabase()); + assertTrue(curs.getCommitGraph().isEmpty()); + commitFile("file.txt", "content", "master"); + GC gc = new GC(db); + gc.gc(); + assertTrue(curs.getCommitGraph().isPresent()); + + db.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_COMMIT_GRAPH, false); + + assertTrue(curs.getCommitGraph().isEmpty()); + } + + @Test public void testShallowFileCorrupt() throws Exception { FileRepository repository = createBareRepository(); ObjectDirectory dir = repository.getObjectDatabase(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index cb91c7931e..6be3620856 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -41,6 +41,7 @@ import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.CoreConfig; import org.eclipse.jgit.lib.ObjectDatabase; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectLoader; @@ -235,7 +236,10 @@ public class ObjectDirectory extends FileObjectDatabase { /** {@inheritDoc} */ @Override public Optional<CommitGraph> getCommitGraph() { - return Optional.ofNullable(fileCommitGraph.get()); + if (config.get(CoreConfig.KEY).enableCommitGraph()) { + return Optional.ofNullable(fileCommitGraph.get()); + } + return Optional.empty(); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java index e7fd7b9e76..fa743babe7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.zip.DataFormatException; import java.util.zip.Inflater; @@ -34,6 +35,7 @@ import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.BitmapIndex; import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder; +import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.InflaterCache; import org.eclipse.jgit.lib.ObjectId; @@ -96,6 +98,12 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs { /** {@inheritDoc} */ @Override + public Optional<CommitGraph> getCommitGraph() { + return db.getCommitGraph(); + } + + /** {@inheritDoc} */ + @Override public Collection<CachedPack> getCachedPacksAndUpdate( BitmapBuilder needBitmap) throws IOException { for (Pack pack : db.getPacks()) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index 081f40e9db..ae0cf42b12 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Optional; import java.util.Set; import org.eclipse.jgit.annotations.NonNull; @@ -27,6 +28,7 @@ import org.eclipse.jgit.internal.revwalk.BitmappedObjectReachabilityChecker; import org.eclipse.jgit.internal.revwalk.BitmappedReachabilityChecker; import org.eclipse.jgit.internal.revwalk.PedestrianObjectReachabilityChecker; import org.eclipse.jgit.internal.revwalk.PedestrianReachabilityChecker; +import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph; import org.eclipse.jgit.revwalk.ObjectReachabilityChecker; import org.eclipse.jgit.revwalk.ObjectWalk; import org.eclipse.jgit.revwalk.ReachabilityChecker; @@ -500,6 +502,23 @@ public abstract class ObjectReader implements AutoCloseable { } /** + * Get the commit-graph for this repository if available. + * <p> + * The commit graph can be created/modified/deleted while the repository is + * open and specific implementations decide when to refresh it. + * + * @return the commit-graph or empty if the commit-graph does not exist or + * is invalid; always returns empty when core.commitGraph is false + * (default is + * {@value org.eclipse.jgit.lib.CoreConfig#DEFAULT_COMMIT_GRAPH_ENABLE}). + * + * @since 6.5 + */ + public Optional<CommitGraph> getCommitGraph() { + return Optional.empty(); + } + + /** * Get the {@link org.eclipse.jgit.lib.ObjectInserter} from which this * reader was created using {@code inserter.newReader()} * @@ -642,6 +661,11 @@ public abstract class ObjectReader implements AutoCloseable { } @Override + public Optional<CommitGraph> getCommitGraph() { + return delegate().getCommitGraph(); + } + + @Override @Nullable public ObjectInserter getCreatedFromInserter() { return delegate().getCreatedFromInserter(); |