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:
Zhen Chen
2016-06-03 15:02:08 -07:00
parent be0d2d89d1
commit 10c815d2e1
8 changed files with 40 additions and 35 deletions

View File

@@ -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 {