Refactor ProjectControl#canReadCommmit to take repository as a parameter
Two reasons: 1. Reusing an existing RevWalk to call isMergedInto or similar on it can corrupt the state in the caller, see I0d242362. 2. The repository is already open before calling this method. Pass the Repo instead of RevWalk and create a new clean RevWalk from the Repo. Change-Id: I00a6d9061d4c690c236e739b29b66b79427cd47b
This commit is contained in:
@@ -49,6 +49,7 @@ import com.google.inject.util.Providers;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.junit.After;
|
||||
@@ -137,7 +138,9 @@ public class ProjectControlTest {
|
||||
ObjectId id = repo.branch("master").commit().create();
|
||||
ProjectControl pc = newProjectControl();
|
||||
RevWalk rw = repo.getRevWalk();
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(id)));
|
||||
Repository r = repo.getRepository();
|
||||
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,8 +153,10 @@ public class ProjectControlTest {
|
||||
|
||||
ProjectControl pc = newProjectControl();
|
||||
RevWalk rw = repo.getRevWalk();
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(id1)));
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(id2)));
|
||||
Repository r = repo.getRepository();
|
||||
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,8 +169,10 @@ public class ProjectControlTest {
|
||||
|
||||
ProjectControl pc = newProjectControl();
|
||||
RevWalk rw = repo.getRevWalk();
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(id1)));
|
||||
assertFalse(pc.canReadCommit(db, rw, rw.parseCommit(id2)));
|
||||
Repository r = repo.getRepository();
|
||||
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
|
||||
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,8 +188,9 @@ public class ProjectControlTest {
|
||||
|
||||
ProjectControl pc = newProjectControl();
|
||||
RevWalk rw = repo.getRevWalk();
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(parent1)));
|
||||
assertFalse(pc.canReadCommit(db, rw, rw.parseCommit(parent2)));
|
||||
Repository r = repo.getRepository();
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
|
||||
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(parent2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,12 +202,14 @@ public class ProjectControlTest {
|
||||
|
||||
ProjectControl pc = newProjectControl();
|
||||
RevWalk rw = repo.getRevWalk();
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(parent1)));
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(id1)));
|
||||
Repository r = repo.getRepository();
|
||||
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
|
||||
|
||||
repo.branch("branch1").update(parent1);
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(parent1)));
|
||||
assertFalse(pc.canReadCommit(db, rw, rw.parseCommit(id1)));
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
|
||||
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -211,12 +221,14 @@ public class ProjectControlTest {
|
||||
|
||||
ProjectControl pc = newProjectControl();
|
||||
RevWalk rw = repo.getRevWalk();
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(parent1)));
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(id1)));
|
||||
Repository r = repo.getRepository();
|
||||
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
|
||||
|
||||
repo.branch("branch1").update(parent1);
|
||||
assertTrue(pc.canReadCommit(db, rw, rw.parseCommit(parent1)));
|
||||
assertFalse(pc.canReadCommit(db, rw, rw.parseCommit(id1)));
|
||||
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
|
||||
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id1)));
|
||||
}
|
||||
|
||||
private ProjectControl newProjectControl() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user