aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-02-01 00:38:52 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2023-02-01 00:41:52 +0100
commitb5de5ccb9e6491a1abafc791db2cc7ac3af74f31 (patch)
tree8c69a9f3482bac6c6715736e79950dd7d95b5740 /org.eclipse.jgit.test
parent21b2aef0aa9f71306733c7724f7ffff3e86206de (diff)
parentda21265a141b68ea3069afd79107f7d374027bc0 (diff)
downloadjgit-b5de5ccb9e6491a1abafc791db2cc7ac3af74f31.tar.gz
jgit-b5de5ccb9e6491a1abafc791db2cc7ac3af74f31.zip
Merge branch 'stable-6.0' into stable-6.1
* stable-6.0: Shortcut during git fetch for avoiding looping through all local refs FetchCommand: fix fetchSubmodules to work on a Ref to a blob Silence API warnings introduced by I466dcde6 Allow the exclusions of refs prefixes from bitmap PackWriterBitmapPreparer: do not include annotated tags in bitmap BatchingProgressMonitor: avoid int overflow when computing percentage Speedup GC listing objects referenced from reflogs FileSnapshotTest: Add more MISSING_FILE coverage Change-Id: Ib5055f2f3b8a313c178d6f6c7c5630285ad5a726
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java14
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java52
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java83
3 files changed, 149 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java
index 5e87b8f59f..12773c2405 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileSnapshotTest.java
@@ -209,6 +209,20 @@ public class FileSnapshotTest {
assertTrue(fs2.equals(fs1));
}
+ @Test
+ public void snapshotAndFileMissingIsNotModified() throws Exception {
+ File doesNotExist = trash.resolve("DOES_NOT_EXIST").toFile();
+ FileSnapshot missing = FileSnapshot.save(doesNotExist);
+ assertFalse(missing.isModified(doesNotExist));
+ }
+
+ @Test
+ public void missingFileEquals() throws Exception {
+ FileSnapshot missing = FileSnapshot.save(
+ trash.resolve("DOES_NOT_EXIST").toFile());
+ assertTrue(missing.equals(FileSnapshot.MISSING_FILE));
+ }
+
@SuppressWarnings("boxing")
@Test
public void detectFileModified() throws IOException {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java
index bb56c84e8e..0c09ad1510 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java
@@ -83,6 +83,40 @@ public class GcCommitSelectionTest extends GcTestCase {
}
@Test
+ public void testBitmapDoesNotIncludeAnnotatedTags() throws Exception {
+ /*
+ * Make sure that the bitmap generated for the following commit
+ * graph does not include commit2 because it is not reachable by any
+ * heads, despite being reachable from tag1 through the annotated-tag1.
+ *
+ * refs/heads/main
+ * ^
+ * |
+ * commit1 <-- commit2 <- annotated-tag1 <- tag1
+ * ^
+ * |
+ * commit0
+ */
+ String mainBranch = "refs/heads/main";
+ BranchBuilder bb = tr.branch(mainBranch);
+
+ String commitMsg = "commit msg";
+ String fileBody = "file body";
+ String tagName = "tag1";
+ bb.commit().message(commitMsg + " 1").add("file1", fileBody).create();
+ RevCommit commit1 = bb.commit().message(commitMsg + " 2").add("file2", fileBody).create();
+ RevCommit commit2 = bb.commit().message(commitMsg + " 3").add("file3", fileBody).create();
+ tr.lightweightTag(tagName, tr.tag(tagName, commit2));
+ tr.branch(mainBranch).update(commit1);
+
+ gc.setExpireAgeMillis(0);
+ gc.gc();
+
+ // Create only 2 bitmaps, for commit0 and commit1, excluding commit2
+ assertEquals(2, gc.getStatistics().numberOfBitmaps);
+ }
+
+ @Test
public void testBitmapSpansWithMerges() throws Exception {
/*
* Commits that are merged. Since 55 is in the oldest history it is
@@ -187,6 +221,24 @@ public class GcCommitSelectionTest extends GcTestCase {
}
@Test
+ public void testBitmapsForExcludedBranches() throws Exception {
+ createNewCommitOnNewBranch("main");
+ createNewCommitOnNewBranch("other");
+ PackConfig packConfig = new PackConfig();
+ packConfig.setBitmapExcludedRefsPrefixes(new String[] { "refs/heads/other" });
+ gc.setPackConfig(packConfig);
+ gc.gc();
+ assertEquals(1,
+ gc.getStatistics().numberOfBitmaps);
+ }
+
+ private void createNewCommitOnNewBranch(String branchName) throws Exception {
+ BranchBuilder bb = tr.branch("refs/heads/" + branchName);
+ String msg = "New branch " + branchName;
+ bb.commit().message(msg).add("some-filename.txt", msg).create();
+ }
+
+ @Test
public void testSelectionOrderingWithChains() throws Exception {
/*-
* Create a history like this, where 'N' is the number of seconds from
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java
new file mode 100644
index 0000000000..55ca2cdea3
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/TextProgressMonitorTest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2023, SAP SE or an SAP affiliate company and others
+ *
+ * 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.lib;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TextProgressMonitorTest {
+
+ private TextProgressMonitor m;
+
+ private ByteArrayOutputStream buf;
+
+ @Before
+ public void setup() {
+ buf = new ByteArrayOutputStream();
+ m = new TextProgressMonitor(
+ new OutputStreamWriter(buf, StandardCharsets.UTF_8));
+ }
+
+ @Test
+ public void testSimple() throws Exception {
+ m.beginTask("task", 10);
+ for (int i = 0; i < 10; i++) {
+ m.update(1);
+ }
+ m.endTask();
+ Assert.assertArrayEquals(
+ new String[] { "", "task: 10% ( 1/10)",
+ "task: 20% ( 2/10)",
+ "task: 30% ( 3/10)",
+ "task: 40% ( 4/10)",
+ "task: 50% ( 5/10)",
+ "task: 60% ( 6/10)",
+ "task: 70% ( 7/10)",
+ "task: 80% ( 8/10)",
+ "task: 90% ( 9/10)",
+ "task: 100% (10/10)",
+ "task: 100% (10/10)\n" },
+ bufLines());
+ }
+
+ @Test
+ public void testLargeNumbers() throws Exception {
+ m.beginTask("task", 1_000_000_000);
+ for (int i = 0; i < 10; i++) {
+ m.update(100_000_000);
+ }
+ m.endTask();
+ Assert.assertArrayEquals(
+ new String[] { "",
+ "task: 10% ( 100000000/1000000000)",
+ "task: 20% ( 200000000/1000000000)",
+ "task: 30% ( 300000000/1000000000)",
+ "task: 40% ( 400000000/1000000000)",
+ "task: 50% ( 500000000/1000000000)",
+ "task: 60% ( 600000000/1000000000)",
+ "task: 70% ( 700000000/1000000000)",
+ "task: 80% ( 800000000/1000000000)",
+ "task: 90% ( 900000000/1000000000)",
+ "task: 100% (1000000000/1000000000)",
+ "task: 100% (1000000000/1000000000)\n" },
+ bufLines());
+ }
+
+ String[] bufLines() throws UnsupportedEncodingException {
+ String s = new String(buf.toString(StandardCharsets.UTF_8.name()));
+ return s.split("\r");
+ }
+}