use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ChangeNotesParser method buildPatchSets.
private Map<PatchSet.Id, PatchSet> buildPatchSets() throws ConfigInvalidException {
Map<PatchSet.Id, PatchSet> result = Maps.newHashMapWithExpectedSize(patchSets.size());
for (Map.Entry<PatchSet.Id, PatchSet.Builder> e : patchSets.entrySet()) {
try {
PatchSet ps = e.getValue().build();
result.put(ps.id(), ps);
} catch (Exception ex) {
ConfigInvalidException cie = parseException("Error building patch set %s", e.getKey());
cie.initCause(ex);
throw cie;
}
}
return result;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ReviewCommand method run.
@Override
protected void run() throws UnloggedFailure {
enableGracefulStop();
if (abandonChange) {
if (restoreChange) {
throw die("abandon and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("abandon and submit actions are mutually exclusive");
}
if (rebaseChange) {
throw die("abandon and rebase actions are mutually exclusive");
}
if (moveToBranch != null) {
throw die("abandon and move actions are mutually exclusive");
}
}
if (json) {
if (restoreChange) {
throw die("json and restore actions are mutually exclusive");
}
if (submitChange) {
throw die("json and submit actions are mutually exclusive");
}
if (abandonChange) {
throw die("json and abandon actions are mutually exclusive");
}
if (changeComment != null) {
throw die("json and message are mutually exclusive");
}
if (rebaseChange) {
throw die("json and rebase actions are mutually exclusive");
}
if (moveToBranch != null) {
throw die("json and move actions are mutually exclusive");
}
if (changeTag != null) {
throw die("json and tag actions are mutually exclusive");
}
}
if (rebaseChange) {
if (submitChange) {
throw die("rebase and submit actions are mutually exclusive");
}
}
boolean ok = true;
ReviewInput input = null;
if (json) {
input = reviewFromJson();
}
for (PatchSet patchSet : patchSets) {
try {
if (input != null) {
applyReview(patchSet, input);
} else {
reviewPatchSet(patchSet);
}
} catch (RestApiException | UnloggedFailure e) {
ok = false;
writeError("error", e.getMessage() + "\n");
} catch (NoSuchChangeException e) {
ok = false;
writeError("error", "no such change " + patchSet.id().changeId().get());
} catch (Exception e) {
ok = false;
writeError("fatal", "internal server error while reviewing " + patchSet.id() + "\n");
logger.atSevere().withCause(e).log("internal error while reviewing %s", patchSet.id());
}
}
if (!ok) {
throw die("one or more reviews failed; review output above");
}
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method commentCanBeCreatedOnOlderPatchset.
@Test
public void commentCanBeCreatedOnOlderPatchset() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
PatchSet.Id previousPatchsetId = changeOperations.change(changeId).currentPatchset().get().patchsetId();
changeOperations.change(changeId).newPatchset().create();
String commentUuid = changeOperations.change(changeId).patchset(previousPatchsetId).newComment().create();
CommentInfo comment = getCommentFromServer(changeId, commentUuid);
assertThat(comment).patchSet().isEqualTo(previousPatchsetId.get());
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class RebaseUtil method findBaseRevision.
/**
* Find the commit onto which a patch set should be rebased.
*
* <p>This is defined as the latest patch set of the change corresponding to this commit's parent,
* or the destination branch tip in the case where the parent's change is merged.
*
* @param patchSet patch set for which the new base commit should be found.
* @param destBranch the destination branch.
* @param git the repository.
* @param rw the RevWalk.
* @return the commit onto which the patch set should be rebased.
* @throws RestApiException if rebase is not possible.
* @throws IOException if accessing the repository fails.
*/
public ObjectId findBaseRevision(PatchSet patchSet, BranchNameKey destBranch, Repository git, RevWalk rw) throws RestApiException, IOException {
ObjectId baseId = null;
RevCommit commit = rw.parseCommit(patchSet.commitId());
if (commit.getParentCount() > 1) {
throw new UnprocessableEntityException("Cannot rebase a change with multiple parents.");
} else if (commit.getParentCount() == 0) {
throw new UnprocessableEntityException("Cannot rebase a change without any parents (is this the initial commit?).");
}
ObjectId parentId = commit.getParent(0);
CHANGES: for (ChangeData cd : queryProvider.get().byBranchCommit(destBranch, parentId.name())) {
for (PatchSet depPatchSet : cd.patchSets()) {
if (!depPatchSet.commitId().equals(parentId)) {
continue;
}
Change depChange = cd.change();
if (depChange.isAbandoned()) {
throw new ResourceConflictException("Cannot rebase a change with an abandoned parent: " + depChange.getKey());
}
if (depChange.isNew()) {
if (depPatchSet.id().equals(depChange.currentPatchSetId())) {
throw new ResourceConflictException("Change is already based on the latest patch set of the dependent change.");
}
baseId = cd.currentPatchSet().commitId();
}
break CHANGES;
}
}
if (baseId == null) {
// We are dependent on a merged PatchSet or have no PatchSet
// dependencies at all.
Ref destRef = git.getRefDatabase().exactRef(destBranch.branch());
if (destRef == null) {
throw new UnprocessableEntityException("The destination branch does not exist: " + destBranch.branch());
}
baseId = destRef.getObjectId();
if (baseId.equals(parentId)) {
throw new ResourceConflictException("Change is already up to date.");
}
}
return baseId;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class PureRevert method get.
public boolean get(ChangeNotes notes, Optional<String> claimedOriginal) throws IOException, BadRequestException, ResourceConflictException {
PatchSet currentPatchSet = notes.getCurrentPatchSet();
if (currentPatchSet == null) {
throw new ResourceConflictException("current revision is missing");
}
if (!claimedOriginal.isPresent()) {
return pureRevertCache.isPureRevert(notes);
}
ObjectId claimedOriginalObjectId;
try {
claimedOriginalObjectId = ObjectId.fromString(claimedOriginal.get());
} catch (InvalidObjectIdException e) {
throw new BadRequestException("invalid object ID", e);
}
return pureRevertCache.isPureRevert(notes.getProjectName(), notes.getCurrentPatchSet().commitId(), claimedOriginalObjectId);
}
Aggregations