summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java33
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java63
3 files changed, 124 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java
new file mode 100644
index 0000000000..b533d5c985
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndexTest.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2023, Google LLC
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.internal.storage.commitgraph;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class GraphObjectIndexTest {
+
+ @Test
+ public void findGraphPosition_noObjInBucket() throws CommitGraphFormatException {
+ GraphObjectIndex idx = new GraphObjectIndex(100,
+ new byte[256 * 4], new byte[] {});
+ int graphPosition = idx.findGraphPosition(
+ ObjectId.fromString("731dfd4c5eb6f88b98e983b9b0551b3562a0c46c"));
+ assertEquals(-1, graphPosition);
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
index 2a403c7699..24a81b6715 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
@@ -542,6 +542,39 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testWriteReverseIndexConfig() {
+ assertFalse(config.isWriteReverseIndex());
+ config.setWriteReverseIndex(true);
+ assertTrue(config.isWriteReverseIndex());
+ }
+
+ @Test
+ public void testWriteReverseIndexOff() throws Exception {
+ config.setWriteReverseIndex(false);
+ writer = new PackWriter(config, db.newObjectReader());
+ ByteArrayOutputStream reverseIndexOutput = new ByteArrayOutputStream();
+
+ writer.writeReverseIndex(reverseIndexOutput);
+
+ assertEquals(0, reverseIndexOutput.size());
+ }
+
+ @Test
+ public void testWriteReverseIndexOn() throws Exception {
+ config.setWriteReverseIndex(true);
+ writeVerifyPack4(false);
+ ByteArrayOutputStream reverseIndexOutput = new ByteArrayOutputStream();
+ int headerBytes = 12;
+ int bodyBytes = 12;
+ int footerBytes = 40;
+
+ writer.writeReverseIndex(reverseIndexOutput);
+
+ assertTrue(reverseIndexOutput.size() == headerBytes + bodyBytes
+ + footerBytes);
+ }
+
+ @Test
public void testExclude() throws Exception {
// TestRepository closes repo
FileRepository repo = createBareRepository();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java
new file mode 100644
index 0000000000..04e372998c
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RewriteGeneratorTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2023, HIS eG
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.revwalk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+
+public class RewriteGeneratorTest extends RevWalkTestCase {
+
+ @Test
+ public void testRewriteGeneratorDoesNotExhaustPreviousGenerator()
+ throws Exception {
+ RevCommit a = commit();
+ a.flags |= RevWalk.TREE_REV_FILTER_APPLIED;
+ RevCommit b = commit(a);
+
+ LIFORevQueue q = new LIFORevQueue();
+ q.add(a);
+ q.add(b);
+
+ /*
+ * Since the TREE_REV_FILTER has been applied to commit a and the
+ * REWRITE flag has not been applied to commit a, the RewriteGenerator
+ * must not rewrite the parent of b and thus must not call the previous
+ * generator (since b already has its correct parent).
+ */
+ RewriteGenerator rewriteGenerator = new RewriteGenerator(q);
+ rewriteGenerator.next();
+
+ assertNotNull(
+ "Previous generator was unnecessarily exhausted by RewriteGenerator",
+ q.next());
+ }
+
+ @Test
+ public void testRewriteGeneratorRewritesParent() throws Exception {
+ RevCommit a = commit();
+ a.flags |= RevWalk.TREE_REV_FILTER_APPLIED;
+ a.flags |= RevWalk.REWRITE;
+ RevCommit b = commit(a);
+ assertEquals(1, b.getParentCount());
+
+ LIFORevQueue q = new LIFORevQueue();
+ /*
+ * We are only adding commit b (and not a), because PendingGenerator
+ * should never emit a commit that has the REWRITE flag set.
+ */
+ q.add(b);
+
+ RewriteGenerator rewriteGenerator = new RewriteGenerator(q);
+ RevCommit returnedB = rewriteGenerator.next();
+ assertEquals(b.getId(), returnedB.getId());
+ assertEquals(0, returnedB.getParentCount());
+ }
+}