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/META-INF/MANIFEST.MF92
-rw-r--r--org.eclipse.jgit.test/pom.xml4
-rw-r--r--org.eclipse.jgit.test/tests.bzl6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java293
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java90
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java95
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java29
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java2
10 files changed, 551 insertions, 64 deletions
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index b54e6a48e7..e0ad0b43d1 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -3,58 +3,58 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.test
Bundle-SymbolicName: org.eclipse.jgit.test
-Bundle-Version: 5.0.1.qualifier
+Bundle-Version: 5.1.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
com.jcraft.jsch;version="[0.1.54,0.2.0)",
- org.eclipse.jgit.api;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.api.errors;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.attributes;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.awtui;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.blame;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.diff;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.dircache;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.errors;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.events;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.fnmatch;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.gitrepo;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.hooks;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.ignore;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.ignore.internal;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.fsck;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.storage.file;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.storage.io;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.storage.pack;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.internal.storage.reftree;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.junit;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.lfs;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.lib;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.merge;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.nls;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.notes;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.patch;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.pgm;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.pgm.internal;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.revplot;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.revwalk;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.revwalk.filter;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.storage.file;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.storage.pack;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.submodule;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.transport;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.transport.http;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.transport.resolver;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.treewalk;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.treewalk.filter;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.util;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.util.io;version="[5.0.1,5.1.0)",
- org.eclipse.jgit.util.sha1;version="[5.0.1,5.1.0)",
+ org.eclipse.jgit.api;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.api.errors;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.attributes;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.awtui;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.blame;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.diff;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.dircache;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.errors;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.events;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.fnmatch;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.gitrepo;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.hooks;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.ignore;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.ignore.internal;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.fsck;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.internal.storage.reftree;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.junit;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.lfs;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.lib;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.merge;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.nls;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.notes;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.patch;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.pgm;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.revplot;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.revwalk;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.storage.file;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.storage.pack;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.submodule;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.transport;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.transport.http;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.treewalk;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.util;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.util.io;version="[5.1.0,5.2.0)",
+ org.eclipse.jgit.util.sha1;version="[5.1.0,5.2.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.experimental.theories;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index 730d3bbe21..c2fd83ed94 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -52,7 +52,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>5.0.1-SNAPSHOT</version>
+ <version>5.1.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.test</artifactId>
@@ -153,7 +153,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <argLine>-Xmx256m -Dfile.encoding=UTF-8 -Djava.io.tmpdir=${project.build.directory}</argLine>
+ <argLine>-Xmx1024m -Dfile.encoding=UTF-8 -Djava.io.tmpdir=${project.build.directory}</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
diff --git a/org.eclipse.jgit.test/tests.bzl b/org.eclipse.jgit.test/tests.bzl
index b1b7b7a9de..64dfe071cf 100644
--- a/org.eclipse.jgit.test/tests.bzl
+++ b/org.eclipse.jgit.test/tests.bzl
@@ -42,6 +42,10 @@ def tests(tests):
'//lib:jsch',
]
+ heap_size = "-Xmx256m"
+ if src.endswith("HugeCommitMessageTest.java"):
+ heap_size = "-Xmx512m"
+
junit_tests(
name = name,
tags = labels,
@@ -57,5 +61,5 @@ def tests(tests):
'//org.eclipse.jgit.lfs:jgit-lfs',
],
flaky = flaky,
- jvm_flags = ["-Xmx256m", "-Dfile.encoding=UTF-8"],
+ jvm_flags = [heap_size, "-Dfile.encoding=UTF-8"],
)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
index 1af37e25f5..ca86d81301 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
@@ -245,7 +245,7 @@ public class PushCommandTest extends RepositoryTestCase {
git.add().addFilepattern("f" + i).call();
commit = git.commit().setMessage("adding f" + i).call();
git.push().setRemote("test").call();
- git2.getRepository().getAllRefs();
+ git2.getRepository().getRefDatabase().getRefs();
assertEquals("failed to update on attempt " + i, commit.getId(),
git2.getRepository().resolve("refs/heads/test"));
}
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 5b567d00f7..bfa30d5b4b 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
@@ -972,7 +972,7 @@ public class DfsGarbageCollectorTest {
private static boolean isReachable(Repository repo, AnyObjectId id)
throws IOException {
try (RevWalk rw = new RevWalk(repo)) {
- for (Ref ref : repo.getAllRefs().values()) {
+ for (Ref ref : repo.getRefDatabase().getRefs()) {
rw.markStart(rw.parseCommit(ref.getObjectId()));
}
for (RevCommit next; (next = rw.next()) != null;) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java
new file mode 100644
index 0000000000..55e1a9c4cc
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2018, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.internal.storage.dfs;
+
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.COMPACT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_REST;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_TXN;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.INSERT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.RECEIVE;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Comparator;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class DfsPackDescriptionTest {
+ private AtomicInteger counter;
+
+ @Before
+ public void setUp() {
+ counter = new AtomicInteger();
+ }
+
+ @Test
+ public void objectLookupComparatorEqual() throws Exception {
+ DfsPackDescription a = create(RECEIVE);
+ a.setFileSize(PACK, 1);
+ a.setFileSize(INDEX, 1);
+ a.setLastModified(1);
+ a.setObjectCount(1);
+ a.setMaxUpdateIndex(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 1);
+ b.setFileSize(INDEX, 2);
+ b.setLastModified(1);
+ b.setObjectCount(1);
+ b.setMaxUpdateIndex(2);
+
+ assertComparesEqual(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorPackSource() throws Exception {
+ DfsPackDescription a = create(COMPACT);
+ a.setFileSize(PACK, 2);
+ a.setLastModified(1);
+ a.setObjectCount(2);
+
+ DfsPackDescription b = create(GC);
+ b.setFileSize(PACK, 1);
+ b.setLastModified(2);
+ b.setObjectCount(1);
+
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorCustomPackSourceComparator()
+ throws Exception {
+ DfsPackDescription a = create(GC);
+
+ DfsPackDescription b = create(COMPACT);
+
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), b, a);
+ assertComparesLessThan(
+ DfsPackDescription.objectLookupComparator(
+ new PackSource.ComparatorBuilder()
+ .add(GC)
+ .add(INSERT, RECEIVE, GC_REST, GC_TXN, UNREACHABLE_GARBAGE)
+ .add(COMPACT)
+ .build()),
+ a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorGcFileSize() throws Exception {
+ // a is older and smaller.
+ DfsPackDescription a = create(GC_REST);
+ a.setFileSize(PACK, 100);
+ a.setLastModified(1);
+ a.setObjectCount(2);
+
+ // b is newer and larger.
+ DfsPackDescription b = create(GC_REST);
+ b.setFileSize(PACK, 200);
+ b.setLastModified(2);
+ b.setObjectCount(1);
+
+ // Since they have the same GC type, tiebreaker is size, and a comes first.
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorNonGcLastModified()
+ throws Exception {
+ // a is older and smaller.
+ DfsPackDescription a = create(INSERT);
+ a.setFileSize(PACK, 100);
+ a.setLastModified(1);
+ a.setObjectCount(2);
+
+ // b is newer and larger.
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 200);
+ b.setLastModified(2);
+ b.setObjectCount(1);
+
+ // Since they have the same type but not GC, tiebreaker is last modified,
+ // and b comes first.
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), b, a);
+ }
+
+ @Test
+ public void objectLookupComparatorObjectCount() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setObjectCount(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setObjectCount(2);
+
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void reftableComparatorEqual() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setFileSize(PACK, 100);
+ a.setObjectCount(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 200);
+ a.setObjectCount(2);
+
+ assertComparesEqual(DfsPackDescription.reftableComparator(), a, b);
+ }
+
+ @Test
+ public void reftableComparatorPackSource() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setMaxUpdateIndex(1);
+ a.setLastModified(1);
+
+ DfsPackDescription b = create(GC);
+ b.setMaxUpdateIndex(2);
+ b.setLastModified(2);
+
+ assertComparesLessThan(DfsPackDescription.reftableComparator(), b, a);
+ }
+
+ @Test
+ public void reftableComparatorMaxUpdateIndex() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setMaxUpdateIndex(1);
+ a.setLastModified(2);
+
+ DfsPackDescription b = create(INSERT);
+ b.setMaxUpdateIndex(2);
+ b.setLastModified(1);
+
+ assertComparesLessThan(DfsPackDescription.reftableComparator(), a, b);
+ }
+
+ @Test
+ public void reftableComparatorLastModified() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setLastModified(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setLastModified(2);
+
+ assertComparesLessThan(DfsPackDescription.reftableComparator(), a, b);
+ }
+
+ @Test
+ public void reuseComparatorEqual() throws Exception {
+ DfsPackDescription a = create(RECEIVE);
+ a.setFileSize(PACK, 1);
+ a.setFileSize(INDEX, 1);
+ a.setLastModified(1);
+ a.setObjectCount(1);
+ a.setMaxUpdateIndex(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 2);
+ b.setFileSize(INDEX, 2);
+ b.setLastModified(2);
+ b.setObjectCount(2);
+ b.setMaxUpdateIndex(2);
+
+ assertComparesEqual(DfsPackDescription.reuseComparator(), a, b);
+ }
+
+ @Test
+ public void reuseComparatorGcPackSize() throws Exception {
+ DfsPackDescription a = create(GC_REST);
+ a.setFileSize(PACK, 1);
+ a.setFileSize(INDEX, 1);
+ a.setLastModified(2);
+ a.setObjectCount(1);
+ a.setMaxUpdateIndex(1);
+
+ DfsPackDescription b = create(GC_REST);
+ b.setFileSize(PACK, 2);
+ b.setFileSize(INDEX, 2);
+ b.setLastModified(1);
+ b.setObjectCount(2);
+ b.setMaxUpdateIndex(2);
+
+ assertComparesLessThan(DfsPackDescription.reuseComparator(), b, a);
+ }
+
+ private DfsPackDescription create(PackSource source) {
+ return new DfsPackDescription(
+ new DfsRepositoryDescription("repo"),
+ "pack_" + counter.incrementAndGet(),
+ source);
+ }
+
+ private static <T> void assertComparesEqual(
+ Comparator<T> comparator, T o1, T o2) {
+ assertEquals(
+ "first object must compare equal to itself",
+ 0, comparator.compare(o1, o1));
+ assertEquals(
+ "second object must compare equal to itself",
+ 0, comparator.compare(o2, o2));
+ assertEquals(
+ "first object must compare equal to second object",
+ 0, comparator.compare(o1, o2));
+ }
+
+ private static <T> void assertComparesLessThan(
+ Comparator<T> comparator, T o1, T o2) {
+ assertEquals(
+ "first object must compare equal to itself",
+ 0, comparator.compare(o1, o1));
+ assertEquals(
+ "second object must compare equal to itself",
+ 0, comparator.compare(o2, o2));
+ assertEquals(
+ "first object must compare less than second object",
+ -1, comparator.compare(o1, o2));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java
new file mode 100644
index 0000000000..7bf1f587f8
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2018, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.internal.storage.dfs;
+
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.COMPACT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.DEFAULT_COMPARATOR;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_REST;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_TXN;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.INSERT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.RECEIVE;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class PackSourceTest {
+ @Test
+ public void defaultComaprator() throws Exception {
+ assertEquals(0, DEFAULT_COMPARATOR.compare(INSERT, INSERT));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(RECEIVE, RECEIVE));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(COMPACT, COMPACT));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(GC, GC));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(GC_REST, GC_REST));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(GC_TXN, GC_TXN));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(UNREACHABLE_GARBAGE, UNREACHABLE_GARBAGE));
+
+ assertEquals(0, DEFAULT_COMPARATOR.compare(INSERT, RECEIVE));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(RECEIVE, INSERT));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(INSERT, COMPACT));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(COMPACT, INSERT));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(RECEIVE, COMPACT));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(COMPACT, RECEIVE));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(COMPACT, GC));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(GC, COMPACT));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(GC, GC_REST));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(GC_REST, GC));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(GC_REST, GC_TXN));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(GC_TXN, GC_REST));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(GC_TXN, UNREACHABLE_GARBAGE));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(UNREACHABLE_GARBAGE, GC_TXN));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java
new file mode 100644
index 0000000000..4193c4ba3e
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.lib;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.WindowCacheConfig;
+import org.eclipse.jgit.storage.pack.PackConfig;
+import org.junit.Test;
+
+public class HugeCommitMessageTest extends RepositoryTestCase {
+
+ private static final int HUGE_SIZE = Math.max(15 * WindowCacheConfig.MB,
+ PackConfig.DEFAULT_BIG_FILE_THRESHOLD + WindowCacheConfig.MB);
+ // Larger than the 5MB fallback limit in RevWalk.getCachedBytes(RevObject
+ // obj, ObjectLoader ldr), and also larger than the default
+ // streamFileThreshold.
+
+ @Test
+ public void testHugeCommitMessage() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("foo", "foo");
+ git.add().addFilepattern("foo").call();
+ WindowCacheConfig wc = new WindowCacheConfig();
+ wc.setStreamFileThreshold(HUGE_SIZE + WindowCacheConfig.MB);
+ wc.install();
+ RevCommit commit = git.commit()
+ .setMessage(insanelyHugeCommitMessage()).call();
+ Ref master = db.findRef("master");
+ List<Ref> actual = git.branchList().setContains(commit.getName())
+ .call();
+ assertTrue("Should be contained in branch master",
+ actual.contains(master));
+ }
+ }
+
+ private String insanelyHugeCommitMessage() {
+ final String oneLine = "012345678901234567890123456789012345678901234567890123456789\n";
+ StringBuilder b = new StringBuilder(HUGE_SIZE + oneLine.length());
+ // Give the message a real header; otherwise even writing the reflog
+ // message may run into troubles because RevCommit.getShortMessage()
+ // will return the whole message.
+ b.append("An insanely huge commit message\n\n");
+ while (b.length() < HUGE_SIZE) {
+ b.append(oneLine);
+ }
+ return b.toString();
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
index 2481e64997..a42027b584 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
@@ -58,7 +58,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
-import java.util.Map;
+import java.util.Optional;
import java.util.TreeSet;
import org.eclipse.jgit.lib.Ref.Storage;
@@ -148,17 +148,22 @@ public class RefTest extends SampleDataRepositoryTestCase {
ObjectId r = db.resolve("refs/remotes/origin/HEAD");
assertEquals(masterId, r);
- Map<String, Ref> allRefs = db.getAllRefs();
- Ref refHEAD = allRefs.get("refs/remotes/origin/HEAD");
- assertNotNull(refHEAD);
- assertEquals(masterId, refHEAD.getObjectId());
- assertFalse(refHEAD.isPeeled());
- assertNull(refHEAD.getPeeledObjectId());
-
- Ref refmaster = allRefs.get("refs/remotes/origin/master");
- assertEquals(masterId, refmaster.getObjectId());
- assertFalse(refmaster.isPeeled());
- assertNull(refmaster.getPeeledObjectId());
+ List<Ref> allRefs = db.getRefDatabase().getRefs();
+ Optional<Ref> refHEAD = allRefs.stream()
+ .filter(ref -> ref.getName().equals("refs/remotes/origin/HEAD"))
+ .findAny();
+ assertTrue(refHEAD.isPresent());
+ assertEquals(masterId, refHEAD.get().getObjectId());
+ assertFalse(refHEAD.get().isPeeled());
+ assertNull(refHEAD.get().getPeeledObjectId());
+
+ Optional<Ref> refmaster = allRefs.stream().filter(
+ ref -> ref.getName().equals("refs/remotes/origin/master"))
+ .findAny();
+ assertTrue(refmaster.isPresent());
+ assertEquals(masterId, refmaster.get().getObjectId());
+ assertFalse(refmaster.get().isPeeled());
+ assertNull(refmaster.get().getPeeledObjectId());
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
index a26ae10af3..cb92a955bc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
@@ -115,7 +115,7 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
}
private void assertContains(RevCommit commit, Collection<Ref> refsThatShouldContainCommit) throws Exception {
- Collection<Ref> allRefs = db.getAllRefs().values();
+ Collection<Ref> allRefs = db.getRefDatabase().getRefs();
Collection<Ref> sortedRefs = RefComparator.sort(allRefs);
List<Ref> actual = RevWalkUtils.findBranchesReachableFrom(commit,
rw, sortedRefs);