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:
Dave Borowitz
2014-10-02 15:26:48 -07:00
committed by David Pursehouse
parent 8dc720ed9b
commit 839650ed0b
3 changed files with 12 additions and 14 deletions

View File

@@ -21,12 +21,22 @@ import com.google.gerrit.server.project.ChangeControl;
import org.eclipse.jgit.lib.AnyObjectId;
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 java.util.List;
/** Extended commit entity with code review specific metadata. */
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) {
final CodeReviewCommit r = new CodeReviewCommit(ObjectId.zeroId());
r.statusCode = s;

View File

@@ -73,7 +73,6 @@ import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@@ -389,12 +388,7 @@ public class MergeOp {
throw new MergeException(m, err);
}
rw = new RevWalk(repo) {
@Override
protected RevCommit createCommit(final AnyObjectId id) {
return new CodeReviewCommit(id);
}
};
rw = CodeReviewCommit.newRevWalk(repo);
rw.sort(RevSort.TOPO);
rw.sort(RevSort.COMMIT_TIME_DESC, true);
canMergeFlag = rw.newFlag("CAN_MERGE");

View File

@@ -35,7 +35,6 @@ import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -112,12 +111,7 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
Repository repo =
args.repoManager.openRepository(otherChange.getProject());
try {
RevWalk rw = new RevWalk(repo) {
@Override
protected RevCommit createCommit(AnyObjectId id) {
return new CodeReviewCommit(id);
}
};
RevWalk rw = CodeReviewCommit.newRevWalk(repo);
try {
RevFlag canMergeFlag = rw.newFlag("CAN_MERGE");
CodeReviewCommit commit =