summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkylezhao <kylezhao@tencent.com>2021-08-12 19:37:58 +0800
committerkylezhao <kylezhao@tencent.com>2021-08-13 10:51:16 +0800
commit35eeab41b3eb3fcf6185dd3714c1c5205c5e15c3 (patch)
treeb0459f560a9170c36cfc33855f158c9475acbd38
parent65de0d4863f76247fd3a8de94176807c02376de8 (diff)
downloadjgit-35eeab41b3eb3fcf6185dd3714c1c5205c5e15c3.tar.gz
jgit-35eeab41b3eb3fcf6185dd3714c1c5205c5e15c3.zip
RevWalk: getMergedInto's result is wrong on the second call
Make sure the future user can reset all UNINTERESTING commmits after this operation. Signed-off-by: kylezhao <kylezhao@tencent.com> Change-Id: I7549b9ff67bd31acd5dfc92331cb9a30b47b8278
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java5
2 files changed, 26 insertions, 1 deletions
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 d9ed0c1c63..200cb6a4fe 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
@@ -76,6 +76,28 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
}
}
+ @Test
+ public void findBranchesReachableManyTimes() throws Exception {
+ /*
+ * a b
+ * | |
+ * c d
+ */
+ RevCommit a = commit();
+ RevCommit b = commit();
+ RevCommit c = commit(a);
+ RevCommit d = commit(b);
+ Ref branchA = branch("a", a);
+ Ref branchB = branch("b", b);
+ Ref branchC = branch("c", c);
+ Ref branchD = branch("d", d);
+
+ assertContains(a, asList(branchA, branchC));
+ assertContains(b, asList(branchB, branchD));
+ assertContains(c, asList(branchC));
+ assertContains(d, asList(branchD));
+ }
+
private Ref branch(String name, RevCommit dst) throws Exception {
return Git.wrap(db).branchCreate().setName(name)
.setStartPoint(dst.name()).call();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
index 5d5ba12baa..d5b3643af9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
@@ -527,10 +527,12 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
private List<Ref> getMergedInto(RevCommit needle, Collection<Ref> haystacks,
Enum returnStrategy, ProgressMonitor monitor) throws IOException {
List<Ref> result = new ArrayList<>();
+ List<RevCommit> uninteresting = new ArrayList<>();
RevFilter oldRF = filter;
TreeFilter oldTF = treeFilter;
try {
finishDelayedFreeFlags();
+ reset(~freeFlags & APP_FLAGS);
filter = RevFilter.ALL;
treeFilter = TreeFilter.ALL;
for (Ref r: haystacks) {
@@ -559,13 +561,14 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
}
if(!commitFound){
markUninteresting(c);
+ uninteresting.add(c);
if (returnStrategy == GetMergedIntoStrategy.RETURN_ON_FIRST_NOT_FOUND) {
return result;
}
}
}
} finally {
- reset(~freeFlags & APP_FLAGS);
+ roots.addAll(uninteresting);
filter = oldRF;
treeFilter = oldTF;
}