aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal
diff options
context:
space:
mode:
authorkylezhao <kylezhao@tencent.com>2021-07-14 10:52:10 +0800
committerkylezhao <kylezhao@tencent.com>2022-12-23 13:06:06 +0800
commit8a7348df6966da39c1402c8f51fa4f7a9aeb8e7e (patch)
treeffa7029fc05059c6ce4673c456af7d940d8cb850 /org.eclipse.jgit.test/tst/org/eclipse/jgit/internal
parent6722f25d565c1acefefb232a45e690507bcd457a (diff)
downloadjgit-8a7348df6966da39c1402c8f51fa4f7a9aeb8e7e.tar.gz
jgit-8a7348df6966da39c1402c8f51fa4f7a9aeb8e7e.zip
CommitGraph: add commit-graph for FileObjectDatabase
This change makes JGit can read .git/objects/info/commit-graph file and then get CommitGraph. Loading a new commit-graph into memory requires additional time. After testing, loading a copy of the Linux's commit-graph(1039139 commits) is under 50ms. Bug: 574368 Change-Id: Iadfdd6ed437945d3cdfdbe988cf541198140a8bf Signed-off-by: kylezhao <kylezhao@tencent.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/internal')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java45
1 files changed, 45 insertions, 0 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 1a3b3787b1..b4ebdcdf8e 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
@@ -43,6 +43,7 @@
package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
@@ -251,6 +252,50 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
IOException.class, () -> dir.getShallowCommits());
}
+ @Test
+ public void testGetCommitGraph() 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);
+
+ // no commit-graph
+ ObjectDirectory dir = db.getObjectDatabase();
+ assertTrue(dir.getCommitGraph().isEmpty());
+
+ // add commit-graph
+ commitFile("file.txt", "content", "master");
+ GC gc = new GC(db);
+ gc.gc();
+ File file = new File(db.getObjectsDirectory(),
+ Constants.INFO_COMMIT_GRAPH);
+ assertTrue(file.exists());
+ assertTrue(file.isFile());
+ assertTrue(dir.getCommitGraph().isPresent());
+ assertEquals(1, dir.getCommitGraph().get().getCommitCnt());
+
+ // update commit-graph
+ commitFile("file2.txt", "content", "master");
+ gc.gc();
+ assertEquals(2, dir.getCommitGraph().get().getCommitCnt());
+
+ // delete commit-graph
+ file.delete();
+ assertFalse(file.exists());
+ assertTrue(dir.getCommitGraph().isEmpty());
+
+ // commit-graph is corrupt
+ try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
+ writer.println("this is a corrupt commit-graph");
+ }
+ assertTrue(dir.getCommitGraph().isEmpty());
+
+ // add commit-graph again
+ gc.gc();
+ assertTrue(dir.getCommitGraph().isPresent());
+ assertEquals(2, dir.getCommitGraph().get().getCommitCnt());
+ }
+
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
final ObjectDirectory dir) {
Callable<ObjectId> callable = () -> dir.newInserter()