use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ChangeData method getDiffSummary.
private Optional<DiffSummary> getDiffSummary() {
if (diffSummary == null) {
if (!lazyload()) {
return Optional.empty();
}
Change c = change();
PatchSet ps = currentPatchSet();
if (c == null || ps == null || !loadCommitData()) {
return Optional.empty();
}
PatchListKey pk = PatchListKey.againstBase(ps.commitId(), parentCount);
DiffSummaryKey key = DiffSummaryKey.fromPatchListKey(pk);
try {
diffSummary = Optional.of(patchListCache.getDiffSummary(key, c.getProject()));
} catch (PatchListNotAvailableException e) {
diffSummary = Optional.empty();
}
}
return diffSummary;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ChangeData method loadCommitData.
private boolean loadCommitData() {
PatchSet ps = currentPatchSet();
if (ps == null) {
return false;
}
try (Repository repo = repoManager.openRepository(project());
RevWalk walk = new RevWalk(repo)) {
RevCommit c = walk.parseCommit(ps.commitId());
commitMessage = c.getFullMessage();
commitFooters = c.getFooterLines();
author = c.getAuthorIdent();
committer = c.getCommitterIdent();
parentCount = c.getParentCount();
} catch (IOException e) {
throw new StorageException(String.format("Loading commit %s for ps %d of change %d failed.", ps.commitId(), ps.id().get(), ps.id().changeId().get()), e);
}
return true;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ListOfFilesUnchangedPredicate method match.
@Override
public boolean match(ApprovalContext ctx) {
PatchSet targetPatchSet = ctx.target();
PatchSet sourcePatchSet = ctx.changeNotes().getPatchSets().get(ctx.patchSetApproval().patchSetId());
Integer parentNum = isInitialCommit(ctx.changeNotes().getProjectName(), targetPatchSet.commitId()) ? 0 : 1;
try {
Map<String, ModifiedFile> baseVsCurrent = diffOperations.loadModifiedFilesAgainstParent(ctx.changeNotes().getProjectName(), targetPatchSet.commitId(), parentNum, DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
Map<String, ModifiedFile> baseVsPrior = diffOperations.loadModifiedFilesAgainstParent(ctx.changeNotes().getProjectName(), sourcePatchSet.commitId(), parentNum, DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
Map<String, ModifiedFile> priorVsCurrent = diffOperations.loadModifiedFiles(ctx.changeNotes().getProjectName(), sourcePatchSet.commitId(), targetPatchSet.commitId(), DiffOptions.DEFAULTS, ctx.revWalk(), ctx.repoConfig());
return match(baseVsCurrent, baseVsPrior, priorVsCurrent);
} catch (DiffNotAvailableException ex) {
throw new StorageException("failed to compute difference in files, so won't copy" + " votes on labels even if list of files is the same and " + "copyAllIfListOfFilesDidNotChange", ex);
}
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class PostReview method batchReviewerEvents.
private void batchReviewerEvents(CurrentUser user, ChangeData cd, PatchSet patchSet, List<ReviewerModification> reviewerModifications, Instant when) {
List<AccountState> newlyAddedReviewers = new ArrayList<>();
// There are no events for CCs and reviewers added/deleted by email.
for (ReviewerModification modification : reviewerModifications) {
Result reviewerAdditionResult = modification.op.getResult();
if (modification.state() == ReviewerState.REVIEWER) {
newlyAddedReviewers.addAll(reviewerAdditionResult.addedReviewers().stream().map(psa -> psa.accountId()).map(accountId -> accountCache.get(accountId)).flatMap(Streams::stream).collect(toList()));
} else if (modification.state() == ReviewerState.REMOVED) {
// There is no batch event for reviewer removals, hence fire the event for each
// modification that deleted a reviewer immediately.
modification.op.sendEvent();
}
}
// Fire a batch event for all newly added reviewers.
reviewerAdded.fire(cd, patchSet, newlyAddedReviewers, user.asIdentifiedUser().state(), when);
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class PutMessage method apply.
@Override
public Response<String> apply(ChangeResource resource, CommitMessageInput input) throws IOException, RestApiException, UpdateException, PermissionBackendException, ConfigInvalidException {
PatchSet ps = psUtil.current(resource.getNotes());
if (ps == null) {
throw new ResourceConflictException("current revision is missing");
}
if (input == null) {
throw new BadRequestException("input cannot be null");
}
String sanitizedCommitMessage = CommitMessageUtil.checkAndSanitizeCommitMessage(input.message);
ensureCanEditCommitMessage(resource.getNotes());
ChangeUtil.ensureChangeIdIsCorrect(projectCache.get(resource.getProject()).orElseThrow(illegalState(resource.getProject())).is(BooleanProjectConfig.REQUIRE_CHANGE_ID), resource.getChange().getKey().get(), sanitizedCommitMessage);
try (Repository repository = repositoryManager.openRepository(resource.getProject());
RevWalk revWalk = new RevWalk(repository);
ObjectInserter objectInserter = repository.newObjectInserter()) {
RevCommit patchSetCommit = revWalk.parseCommit(ps.commitId());
String currentCommitMessage = patchSetCommit.getFullMessage();
if (input.message.equals(currentCommitMessage)) {
throw new ResourceConflictException("new and existing commit message are the same");
}
Instant ts = TimeUtil.now();
try (BatchUpdate bu = updateFactory.create(resource.getChange().getProject(), userProvider.get(), ts)) {
// Ensure that BatchUpdate will update the same repo
bu.setRepository(repository, new RevWalk(objectInserter.newReader()), objectInserter);
PatchSet.Id psId = ChangeUtil.nextPatchSetId(repository, ps.id());
ObjectId newCommit = createCommit(objectInserter, patchSetCommit, sanitizedCommitMessage, ts);
PatchSetInserter inserter = psInserterFactory.create(resource.getNotes(), psId, newCommit);
inserter.setMessage(String.format("Patch Set %s: Commit message was updated.", psId.getId()));
inserter.setDescription("Edit commit message");
bu.setNotify(resolveNotify(input, resource));
bu.addOp(resource.getChange().getId(), inserter);
bu.execute();
}
}
return Response.ok("ok");
}
Aggregations