CodeReviewCommit: Add a static method to create a RevWalk
Several places in the code construct a new RevWalk subclass that produces CodeReviewCommits. Consolidate these into a single method. Change-Id: If38a648fb95d86f8f8297d1ddacfb9e62a96c8e3
This commit is contained in:
committed by
David Pursehouse
parent
8dc720ed9b
commit
839650ed0b
@@ -21,12 +21,22 @@ import com.google.gerrit.server.project.ChangeControl;
|
|||||||
|
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
import org.eclipse.jgit.lib.AnyObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Extended commit entity with code review specific metadata. */
|
/** Extended commit entity with code review specific metadata. */
|
||||||
public class CodeReviewCommit extends RevCommit {
|
public class CodeReviewCommit extends RevCommit {
|
||||||
|
public static RevWalk newRevWalk(Repository repo) {
|
||||||
|
return new RevWalk(repo) {
|
||||||
|
@Override
|
||||||
|
protected RevCommit createCommit(AnyObjectId id) {
|
||||||
|
return new CodeReviewCommit(id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
static CodeReviewCommit error(final CommitMergeStatus s) {
|
static CodeReviewCommit error(final CommitMergeStatus s) {
|
||||||
final CodeReviewCommit r = new CodeReviewCommit(ObjectId.zeroId());
|
final CodeReviewCommit r = new CodeReviewCommit(ObjectId.zeroId());
|
||||||
r.statusCode = s;
|
r.statusCode = s;
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.ObjectInserter;
|
import org.eclipse.jgit.lib.ObjectInserter;
|
||||||
@@ -389,12 +388,7 @@ public class MergeOp {
|
|||||||
throw new MergeException(m, err);
|
throw new MergeException(m, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
rw = new RevWalk(repo) {
|
rw = CodeReviewCommit.newRevWalk(repo);
|
||||||
@Override
|
|
||||||
protected RevCommit createCommit(final AnyObjectId id) {
|
|
||||||
return new CodeReviewCommit(id);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
rw.sort(RevSort.TOPO);
|
rw.sort(RevSort.TOPO);
|
||||||
rw.sort(RevSort.COMMIT_TIME_DESC, true);
|
rw.sort(RevSort.COMMIT_TIME_DESC, true);
|
||||||
canMergeFlag = rw.newFlag("CAN_MERGE");
|
canMergeFlag = rw.newFlag("CAN_MERGE");
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import com.google.gwtorm.server.OrmException;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
@@ -112,12 +111,7 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
|
|||||||
Repository repo =
|
Repository repo =
|
||||||
args.repoManager.openRepository(otherChange.getProject());
|
args.repoManager.openRepository(otherChange.getProject());
|
||||||
try {
|
try {
|
||||||
RevWalk rw = new RevWalk(repo) {
|
RevWalk rw = CodeReviewCommit.newRevWalk(repo);
|
||||||
@Override
|
|
||||||
protected RevCommit createCommit(AnyObjectId id) {
|
|
||||||
return new CodeReviewCommit(id);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
RevFlag canMergeFlag = rw.newFlag("CAN_MERGE");
|
RevFlag canMergeFlag = rw.newFlag("CAN_MERGE");
|
||||||
CodeReviewCommit commit =
|
CodeReviewCommit commit =
|
||||||
|
|||||||
Reference in New Issue
Block a user