assertThrows(IOException.class, () -> mock.open(curs, id));
}
+ @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();
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;
/** {@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();
}
/**
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;
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;
return null;
}
+ /** {@inheritDoc} */
+ @Override
+ public Optional<CommitGraph> getCommitGraph() {
+ return db.getCommitGraph();
+ }
+
/** {@inheritDoc} */
@Override
public Collection<CachedPack> getCachedPacksAndUpdate(
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;
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;
return new PedestrianObjectReachabilityChecker(ow);
}
+ /**
+ * 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()}
return delegate().getBitmapIndex();
}
+ @Override
+ public Optional<CommitGraph> getCommitGraph() {
+ return delegate().getCommitGraph();
+ }
+
@Override
@Nullable
public ObjectInserter getCreatedFromInserter() {