use of com.google.gerrit.server.edit.ChangeEdit in project gerrit by GerritCodeReview.
the class PatchScriptFactory method call.
@Override
public PatchScript call() throws LargeObjectException, AuthException, InvalidChangeOperationException, IOException, PermissionBackendException {
try {
permissionBackend.user(currentUser).change(notes).check(ChangePermission.READ);
} catch (AuthException e) {
throw new NoSuchChangeException(changeId, e);
}
if (!projectCache.get(notes.getProjectName()).map(ProjectState::statePermitsRead).orElse(false)) {
throw new NoSuchChangeException(changeId);
}
try (Repository git = repoManager.openRepository(notes.getProjectName())) {
try {
validatePatchSetId(psa);
validatePatchSetId(psb);
ObjectId aId = getAId().orElse(null);
ObjectId bId = getBId().orElse(null);
if (bId == null) {
// Change edit: create synthetic PatchSet corresponding to the edit.
Optional<ChangeEdit> edit = editReader.byChange(notes);
if (!edit.isPresent()) {
throw new NoSuchChangeException(notes.getChangeId());
}
bId = edit.get().getEditCommit();
}
return getPatchScript(git, aId, bId);
} catch (DiffNotAvailableException e) {
throw new StorageException(e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("File content unavailable");
throw new NoSuchChangeException(changeId, e);
} catch (org.eclipse.jgit.errors.LargeObjectException err) {
throw new LargeObjectException("File content is too large", err);
}
} catch (RepositoryNotFoundException e) {
logger.atSevere().withCause(e).log("Repository %s not found", notes.getProjectName());
throw new NoSuchChangeException(changeId, e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("Cannot open repository %s", notes.getProjectName());
throw new NoSuchChangeException(changeId, e);
}
}
use of com.google.gerrit.server.edit.ChangeEdit in project gerrit by GerritCodeReview.
the class ApplyFix method apply.
@Override
public Response<EditInfo> apply(FixResource fixResource, Input nothing) throws AuthException, BadRequestException, ResourceConflictException, IOException, ResourceNotFoundException, PermissionBackendException {
RevisionResource revisionResource = fixResource.getRevisionResource();
Project.NameKey project = revisionResource.getProject();
ProjectState projectState = projectCache.get(project).orElseThrow(illegalState(project));
PatchSet patchSet = revisionResource.getPatchSet();
try (Repository repository = gitRepositoryManager.openRepository(project)) {
CommitModification commitModification = fixReplacementInterpreter.toCommitModification(repository, projectState, patchSet.commitId(), fixResource.getFixReplacements());
ChangeEdit changeEdit = changeEditModifier.combineWithModifiedPatchSetTree(repository, revisionResource.getNotes(), patchSet, commitModification);
return Response.ok(changeEditJson.toEditInfo(changeEdit, false));
} catch (InvalidChangeOperationException e) {
throw new ResourceConflictException(e.getMessage());
}
}
Aggregations