Move ChangeUtil#getMessage method into GetContent
GetContent is the only caller of this method. Having this method moved out of ChangeUtil will allow us to make ChangeUtil just be a collection of static methods once Revert is converted to use BatchUpdate. Change-Id: I577249644032bde7d51446e48194de13464212fa Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -31,7 +31,6 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.UpdateException;
|
||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||
import com.google.gerrit.server.mail.RevertedSender;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
@@ -284,26 +283,6 @@ public class ChangeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage(ChangeNotes notes)
|
||||
throws NoSuchChangeException, OrmException,
|
||||
MissingObjectException, IncorrectObjectTypeException, IOException {
|
||||
Change.Id changeId = notes.getChangeId();
|
||||
PatchSet ps = psUtil.current(db.get(), notes);
|
||||
if (ps == null) {
|
||||
throw new NoSuchChangeException(changeId);
|
||||
}
|
||||
|
||||
try (Repository git =
|
||||
gitManager.openRepository(notes.getProjectName());
|
||||
RevWalk revWalk = new RevWalk(git)) {
|
||||
RevCommit commit = revWalk.parseCommit(
|
||||
ObjectId.fromString(ps.getRevision().get()));
|
||||
return commit.getFullMessage();
|
||||
} catch (RepositoryNotFoundException e) {
|
||||
throw new NoSuchChangeException(changeId, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PatchSet.Id nextPatchSetId(PatchSet.Id id) {
|
||||
return new PatchSet.Id(id.getParentKey(), id.get() + 1);
|
||||
}
|
||||
|
||||
@@ -17,27 +17,44 @@ package com.google.gerrit.server.change;
|
||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
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.io.IOException;
|
||||
|
||||
@Singleton
|
||||
public class GetContent implements RestReadView<FileResource> {
|
||||
private final Provider<ReviewDb> db;
|
||||
private final GitRepositoryManager gitManager;
|
||||
private final PatchSetUtil psUtil;
|
||||
private final FileContentUtil fileContentUtil;
|
||||
private final ChangeUtil changeUtil;
|
||||
|
||||
@Inject
|
||||
GetContent(FileContentUtil fileContentUtil,
|
||||
ChangeUtil changeUtil) {
|
||||
GetContent(
|
||||
Provider<ReviewDb> db,
|
||||
GitRepositoryManager gitManager,
|
||||
PatchSetUtil psUtil,
|
||||
FileContentUtil fileContentUtil) {
|
||||
this.db = db;
|
||||
this.gitManager = gitManager;
|
||||
this.psUtil = psUtil;
|
||||
this.fileContentUtil = fileContentUtil;
|
||||
this.changeUtil = changeUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +63,7 @@ public class GetContent implements RestReadView<FileResource> {
|
||||
OrmException {
|
||||
String path = rsrc.getPatchKey().get();
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
String msg = changeUtil.getMessage(
|
||||
String msg = getMessage(
|
||||
rsrc.getRevision().getChangeResource().getNotes());
|
||||
return BinaryResult.create(msg)
|
||||
.setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
|
||||
@@ -57,4 +74,22 @@ public class GetContent implements RestReadView<FileResource> {
|
||||
ObjectId.fromString(rsrc.getRevision().getPatchSet().getRevision().get()),
|
||||
path);
|
||||
}
|
||||
|
||||
private String getMessage(ChangeNotes notes)
|
||||
throws NoSuchChangeException, OrmException, IOException {
|
||||
Change.Id changeId = notes.getChangeId();
|
||||
PatchSet ps = psUtil.current(db.get(), notes);
|
||||
if (ps == null) {
|
||||
throw new NoSuchChangeException(changeId);
|
||||
}
|
||||
|
||||
try (Repository git = gitManager.openRepository(notes.getProjectName());
|
||||
RevWalk revWalk = new RevWalk(git)) {
|
||||
RevCommit commit = revWalk.parseCommit(
|
||||
ObjectId.fromString(ps.getRevision().get()));
|
||||
return commit.getFullMessage();
|
||||
} catch (RepositoryNotFoundException e) {
|
||||
throw new NoSuchChangeException(changeId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user