aboutsummaryrefslogtreecommitdiffstats
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/dfs/DfsGarbageCollectorTest.java36
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java30
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java30
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java27
4 files changed, 123 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
index 1bff27e26a..e193de9764 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
@@ -31,6 +31,8 @@ import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.BatchRefUpdate;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
@@ -1122,6 +1124,40 @@ public class DfsGarbageCollectorTest {
}
@Test
+ public void testReadChangedPathConfigAsFalse() throws Exception {
+ String head = "refs/heads/head1";
+ git.branch(head).commit().message("0").noParents().create();
+ gcWithCommitGraphAndBloomFilter();
+
+ Config repoConfig = odb.getRepository().getConfig();
+ repoConfig.setBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION, null,
+ ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, false);
+
+ DfsPackFile gcPack = odb.getPacks()[0];
+ try (DfsReader reader = odb.newReader()) {
+ CommitGraph cg = gcPack.getCommitGraph(reader);
+ assertNull(cg.getChangedPathFilter(0));
+ }
+ }
+
+ @Test
+ public void testReadChangedPathConfigAsTrue() throws Exception {
+ String head = "refs/heads/head1";
+ git.branch(head).commit().message("0").noParents().create();
+ gcWithCommitGraphAndBloomFilter();
+
+ Config repoConfig = odb.getRepository().getConfig();
+ repoConfig.setBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION, null,
+ ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, true);
+
+ DfsPackFile gcPack = odb.getPacks()[0];
+ try (DfsReader reader = odb.newReader()) {
+ CommitGraph cg = gcPack.getCommitGraph(reader);
+ assertNotNull(cg.getChangedPathFilter(0));
+ }
+ }
+
+ @Test
public void objectSizeIdx_reachableBlob_bigEnough_indexed() throws Exception {
String master = "refs/heads/master";
RevCommit root = git.branch(master).commit().message("root").noParents()
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
index 44694acc8d..d21e51f276 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
@@ -10,7 +10,9 @@
package org.eclipse.jgit.internal.storage.dfs;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -24,6 +26,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.zip.Deflater;
+import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
import org.eclipse.jgit.internal.storage.dfs.DfsReader.PackLoadListener;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
@@ -31,6 +34,7 @@ import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
import org.eclipse.jgit.internal.storage.pack.PackWriter;
import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.Constants;
@@ -263,6 +267,27 @@ public class DfsPackFileTest {
assertEquals(2, tal.blockLoadCount);
}
+ @Test
+ public void testExistenceOfBloomFilterAlongWithCommitGraph()
+ throws Exception {
+ try (TestRepository<InMemoryRepository> repository = new TestRepository<>(
+ db)) {
+ repository.branch("/refs/heads/main").commit().add("blob1", "blob1")
+ .create();
+ }
+ setReadChangedPaths(true);
+ DfsGarbageCollector gc = new DfsGarbageCollector(db);
+ gc.setWriteCommitGraph(true).setWriteBloomFilter(true)
+ .pack(NullProgressMonitor.INSTANCE);
+
+ DfsReader reader = db.getObjectDatabase().newReader();
+ CommitGraph cg = db.getObjectDatabase().getPacks()[0]
+ .getCommitGraph(reader);
+ assertNotNull(cg);
+ assertEquals(1, cg.getCommitCnt());
+ assertNotNull(cg.getChangedPathFilter(0));
+ }
+
private ObjectId setupPack(int bs, int ps) throws IOException {
DfsBlockCacheConfig cfg = new DfsBlockCacheConfig().setBlockSize(bs)
.setBlockLimit(bs * 100).setStreamRatio(bypassCache ? 0F : 1F);
@@ -298,4 +323,9 @@ public class DfsPackFileTest {
db.getConfig().setInt(CONFIG_PACK_SECTION, null,
CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX, threshold);
}
+
+ private void setReadChangedPaths(boolean enable) {
+ db.getConfig().setBoolean(CONFIG_COMMIT_GRAPH_SECTION, null,
+ CONFIG_KEY_READ_CHANGED_PATHS, enable);
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java
index 8215a795b2..c2f8f10631 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCommitGraphTest.java
@@ -38,6 +38,7 @@ import org.eclipse.jgit.revwalk.filter.RevFilter;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.junit.Test;
@@ -197,6 +198,35 @@ public class RevWalkCommitGraphTest extends RevWalkTestCase {
}
@Test
+ public void testChangedPathFilterWithMultiPaths() throws Exception {
+ RevCommit c1 = commitFile("file1", "1", "master");
+ RevCommit c2 = commitFile("file1", "2", "master");
+ RevCommit c3 = commitFile("file2", "3", "master");
+ RevCommit c4 = commitFile("file3", "4", "master");
+
+ enableAndWriteCommitGraph();
+
+ TreeRevFilter trf = new TreeRevFilter(rw,
+ PathFilterGroup.createFromStrings(List.of("file1", "file2")));
+ rw.markStart(rw.lookupCommit(c4));
+ rw.setRevFilter(trf);
+ assertEquals(c3, rw.next());
+ assertEquals(c2, rw.next());
+ assertEquals(c1, rw.next());
+ assertNull(rw.next());
+
+ // c2 and c3 has either file1 or file2, c1 did not use ChangedPathFilter
+ // since it has no parent
+ assertEquals(2, trf.getChangedPathFilterTruePositive());
+
+ // No false positives
+ assertEquals(0, trf.getChangedPathFilterFalsePositive());
+
+ // c4 does not match either file1 or file2
+ assertEquals(1, trf.getChangedPathFilterNegative());
+ }
+
+ @Test
public void testChangedPathFilterWithFollowFilter() throws Exception {
RevCommit c0 = commit(tree());
RevCommit c1 = commit(tree(file("file", blob("contents"))), c0);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
index 32bd40312f..1bb4939c85 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
@@ -11,6 +11,7 @@
package org.eclipse.jgit.treewalk.filter;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -21,7 +22,9 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
@@ -30,6 +33,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StopWalkException;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Sets;
@@ -143,6 +147,29 @@ public class PathFilterGroupTest {
}
@Test
+ public void testGetPathsBestEffort() {
+ String[] paths = { "path1", "path2", "path3" };
+ Set<byte[]> expected = Arrays.stream(paths).map(Constants::encode)
+ .collect(Collectors.toSet());
+ TreeFilter pathFilterGroup = PathFilterGroup.createFromStrings(paths);
+ Optional<Set<byte[]>> bestEffortPaths = pathFilterGroup
+ .getPathsBestEffort();
+ assertTrue(bestEffortPaths.isPresent());
+ Set<byte[]> actual = bestEffortPaths.get();
+ assertEquals(expected.size(), actual.size());
+ for (byte[] actualPath : actual) {
+ boolean findMatch = false;
+ for (byte[] expectedPath : expected) {
+ if (Arrays.equals(actualPath, expectedPath)) {
+ findMatch = true;
+ break;
+ }
+ }
+ assertTrue(findMatch);
+ }
+ }
+
+ @Test
public void testStopWalk() throws MissingObjectException,
IncorrectObjectTypeException, IOException {
// Obvious