Revert: Move check for initial commit up to fail early

Change-Id: I57add0be21965daf6317c48fc1737255b21b6aa8
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-02-16 13:38:17 +01:00
parent 506b818ce8
commit 0c9af107f5

View File

@@ -151,16 +151,15 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
RevWalk revWalk = new RevWalk(git)) { RevWalk revWalk = new RevWalk(git)) {
RevCommit commitToRevert = RevCommit commitToRevert =
revWalk.parseCommit(ObjectId.fromString(patch.getRevision().get())); revWalk.parseCommit(ObjectId.fromString(patch.getRevision().get()));
if (commitToRevert.getParentCount() == 0) {
throw new ResourceConflictException("Cannot revert initial commit");
}
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
PersonIdent committerIdent = new PersonIdent(serverIdent, now); PersonIdent committerIdent = new PersonIdent(serverIdent, now);
PersonIdent authorIdent = user.asIdentifiedUser() PersonIdent authorIdent = user.asIdentifiedUser()
.newCommitterIdent(now, committerIdent.getTimeZone()); .newCommitterIdent(now, committerIdent.getTimeZone());
if (commitToRevert.getParentCount() == 0) {
throw new ResourceConflictException("Cannot revert initial commit");
}
RevCommit parentToCommitToRevert = commitToRevert.getParent(0); RevCommit parentToCommitToRevert = commitToRevert.getParent(0);
revWalk.parseHeaders(parentToCommitToRevert); revWalk.parseHeaders(parentToCommitToRevert);