summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorAdithya Chakilam <quic_achakila@quicinc.com>2021-02-18 13:41:19 -0600
committerMatthias Sohn <matthias.sohn@sap.com>2021-03-14 13:45:29 +0100
commit0bd2f4bf77c856213e09d656a948e71f71cfd038 (patch)
treefb36301086599d7c891e2a79fdfa1b48c546b23a /org.eclipse.jgit.test
parent4a78d911c578a6f9028d6e74b5668dfc384ef80f (diff)
downloadjgit-0bd2f4bf77c856213e09d656a948e71f71cfd038.tar.gz
jgit-0bd2f4bf77c856213e09d656a948e71f71cfd038.zip
Introduce getMergedInto(RevCommit commit, Collection<Ref> refs)
In cases where we need to determine if a given commit is merged into many refs, using isMergedInto(base, tip) for each ref would cause multiple unwanted walks. getMergedInto() marks the unreachable commits as uninteresting which would then avoid walking that same path again. Using the same api, also introduce isMergedIntoAny() and isMergedIntoAll() Change-Id: I65de9873dce67af9c415d1d236bf52d31b67e8fe Signed-off-by: Adithya Chakilam <quic_achakila@quicinc.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergedIntoTest.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergedIntoTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergedIntoTest.java
index 2c21eb60d3..2f16aa49e8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergedIntoTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkMergedIntoTest.java
@@ -11,6 +11,9 @@ package org.eclipse.jgit.revwalk;
import static org.junit.Assert.assertTrue;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.eclipse.jgit.lib.Ref;
import org.junit.Test;
public class RevWalkMergedIntoTest extends RevWalkTestCase {
@@ -44,4 +47,82 @@ public class RevWalkMergedIntoTest extends RevWalkTestCase {
final RevCommit t = commit(n, o);
assertTrue(rw.isMergedInto(b, t));
}
+
+ @Test
+ public void testGetMergedInto() throws Exception {
+ /*
+ * i
+ * / \
+ * A o
+ * / \ \
+ * o1 o2 E
+ * / \ / \
+ * B C D
+ */
+ String b = "refs/heads/b";
+ String c = "refs/heads/c";
+ String d = "refs/heads/d";
+ String e = "refs/heads/e";
+ final RevCommit i = commit();
+ final RevCommit a = commit(i);
+ final RevCommit o1 = commit(a);
+ final RevCommit o2 = commit(a);
+ createBranch(commit(o1), b);
+ createBranch(commit(o1, o2), c);
+ createBranch(commit(o2), d);
+ createBranch(commit(commit(i)), e);
+
+ List<String> modifiedResult = rw.getMergedInto(a, getRefs())
+ .stream().map(Ref::getName).collect(Collectors.toList());
+
+ assertTrue(modifiedResult.size() == 3);
+ assertTrue(modifiedResult.contains(b));
+ assertTrue(modifiedResult.contains(c));
+ assertTrue(modifiedResult.contains(d));
+ }
+
+ @Test
+ public void testIsMergedIntoAny() throws Exception {
+ /*
+ * i
+ * / \
+ * A o
+ * / \
+ * o C
+ * /
+ * B
+ */
+ String b = "refs/heads/b";
+ String c = "refs/heads/c";
+ final RevCommit i = commit();
+ final RevCommit a = commit(i);
+ createBranch(commit(commit(a)), b);
+ createBranch(commit(commit(i)), c);
+
+ assertTrue( rw.isMergedIntoAny(a, getRefs()));
+ }
+
+ @Test
+ public void testIsMergedIntoAll() throws Exception {
+ /*
+ *
+ * A
+ * / \
+ * o1 o2
+ * / \ / \
+ * B C D
+ */
+
+ String b = "refs/heads/b";
+ String c = "refs/heads/c";
+ String d = "refs/heads/c";
+ final RevCommit a = commit();
+ final RevCommit o1 = commit(a);
+ final RevCommit o2 = commit(a);
+ createBranch(commit(o1), b);
+ createBranch(commit(o1, o2), c);
+ createBranch(commit(o2), d);
+
+ assertTrue(rw.isMergedIntoAll(a, getRefs()));
+ }
}