Search in sources :

Example 6 with ChangeEdit

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);
    }
}
Also used : ChangeEdit(com.google.gerrit.server.edit.ChangeEdit) ObjectId(org.eclipse.jgit.lib.ObjectId) AuthException(com.google.gerrit.extensions.restapi.AuthException) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) LargeObjectException(com.google.gerrit.server.git.LargeObjectException) Repository(org.eclipse.jgit.lib.Repository) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ProjectState(com.google.gerrit.server.project.ProjectState) StorageException(com.google.gerrit.exceptions.StorageException)

Example 7 with ChangeEdit

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());
    }
}
Also used : Project(com.google.gerrit.entities.Project) InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) Repository(org.eclipse.jgit.lib.Repository) ChangeEdit(com.google.gerrit.server.edit.ChangeEdit) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) CommitModification(com.google.gerrit.server.edit.CommitModification) RevisionResource(com.google.gerrit.server.change.RevisionResource) ProjectState(com.google.gerrit.server.project.ProjectState) PatchSet(com.google.gerrit.entities.PatchSet)

Aggregations

ChangeEdit (com.google.gerrit.server.edit.ChangeEdit)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 PatchSet (com.google.gerrit.entities.PatchSet)3 ProjectState (com.google.gerrit.server.project.ProjectState)3 Repository (org.eclipse.jgit.lib.Repository)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 RevisionResource (com.google.gerrit.server.change.RevisionResource)2 InvalidChangeOperationException (com.google.gerrit.server.project.InvalidChangeOperationException)2 NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)2 IOException (java.io.IOException)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 Change (com.google.gerrit.entities.Change)1 Patch (com.google.gerrit.entities.Patch)1 Project (com.google.gerrit.entities.Project)1 StorageException (com.google.gerrit.exceptions.StorageException)1 PublishChangeEditInput (com.google.gerrit.extensions.api.changes.PublishChangeEditInput)1 Project (com.google.gerrit.reviewdb.client.Project)1 RevId (com.google.gerrit.reviewdb.client.RevId)1 CommitModification (com.google.gerrit.server.edit.CommitModification)1