Search in sources :

Example 11 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class ReviewCommand method run.

@Override
protected void run() throws UnloggedFailure {
    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 (publishPatchSet) {
            throw die("abandon and publish actions are mutually exclusive");
        }
        if (deleteDraftPatchSet) {
            throw die("abandon and delete 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 (publishPatchSet) {
        if (restoreChange) {
            throw die("publish and restore actions are mutually exclusive");
        }
        if (submitChange) {
            throw die("publish and submit actions are mutually exclusive");
        }
        if (deleteDraftPatchSet) {
            throw die("publish and delete 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 (deleteDraftPatchSet) {
            throw die("json and delete actions are mutually exclusive");
        }
        if (publishPatchSet) {
            throw die("json and publish 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 (deleteDraftPatchSet) {
            throw die("rebase and delete actions are mutually exclusive");
        }
        if (submitChange) {
            throw die("rebase and submit actions are mutually exclusive");
        }
    }
    if (deleteDraftPatchSet && submitChange) {
        throw die("delete and submit actions are mutually exclusive");
    }
    boolean ok = true;
    ReviewInput input = null;
    if (json) {
        input = reviewFromJson();
    }
    for (final 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.getId().getParentKey().get());
        } catch (Exception e) {
            ok = false;
            writeError("fatal", "internal server error while reviewing " + patchSet.getId() + "\n");
            log.error("internal error while reviewing " + patchSet.getId(), e);
        }
    }
    if (!ok) {
        throw die("one or more reviews failed; review output above");
    }
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) OrmException(com.google.gwtorm.server.OrmException) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) JsonSyntaxException(com.google.gson.JsonSyntaxException) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) IOException(java.io.IOException)

Example 12 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class ChangeIsVisibleToPredicate method match.

@Override
public boolean match(final ChangeData cd) throws OrmException {
    if (cd.fastIsVisibleTo(user)) {
        return true;
    }
    try {
        Change c = cd.change();
        if (c == null) {
            return false;
        }
        ChangeNotes notes = notesFactory.createFromIndexedChange(c);
        ChangeControl cc = changeControl.controlFor(notes, user);
        if (cc.isVisible(db.get(), cd)) {
            cd.cacheVisibleTo(cc);
            return true;
        }
    } catch (NoSuchChangeException e) {
    // Ignored
    }
    return false;
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ChangeControl(com.google.gerrit.server.project.ChangeControl) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes)

Example 13 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class GetContent method getMergeList.

private byte[] getMergeList(ChangeNotes notes) throws OrmException, IOException {
    Change.Id changeId = notes.getChangeId();
    PatchSet ps = psUtil.current(db.get(), notes);
    if (ps == null) {
        throw new NoSuchChangeException(changeId);
    }
    try (Repository git = gitManager.openRepository(notes.getProjectName());
        RevWalk revWalk = new RevWalk(git)) {
        return Text.forMergeList(ComparisonType.againstAutoMerge(), revWalk.getObjectReader(), ObjectId.fromString(ps.getRevision().get())).getContent();
    } catch (RepositoryNotFoundException e) {
        throw new NoSuchChangeException(changeId, e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 14 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class GetDiff method apply.

@Override
public Response<DiffInfo> apply(FileResource resource) throws ResourceConflictException, ResourceNotFoundException, OrmException, AuthException, InvalidChangeOperationException, IOException {
    DiffPreferencesInfo prefs = new DiffPreferencesInfo();
    if (whitespace != null) {
        prefs.ignoreWhitespace = whitespace;
    } else if (ignoreWhitespace != null) {
        prefs.ignoreWhitespace = ignoreWhitespace.whitespace;
    } else {
        prefs.ignoreWhitespace = Whitespace.IGNORE_LEADING_AND_TRAILING;
    }
    prefs.context = context;
    prefs.intralineDifference = intraline;
    PatchScriptFactory psf;
    PatchSet basePatchSet = null;
    if (base != null) {
        RevisionResource baseResource = revisions.parse(resource.getRevision().getChangeResource(), IdString.fromDecoded(base));
        basePatchSet = baseResource.getPatchSet();
        psf = patchScriptFactoryFactory.create(resource.getRevision().getControl(), resource.getPatchKey().getFileName(), basePatchSet.getId(), resource.getPatchKey().getParentKey(), prefs);
    } else if (parentNum > 0) {
        psf = patchScriptFactoryFactory.create(resource.getRevision().getControl(), resource.getPatchKey().getFileName(), parentNum - 1, resource.getPatchKey().getParentKey(), prefs);
    } else {
        psf = patchScriptFactoryFactory.create(resource.getRevision().getControl(), resource.getPatchKey().getFileName(), null, resource.getPatchKey().getParentKey(), prefs);
    }
    try {
        psf.setLoadHistory(false);
        psf.setLoadComments(context != DiffPreferencesInfo.WHOLE_FILE_CONTEXT);
        PatchScript ps = psf.call();
        Content content = new Content(ps);
        for (Edit edit : ps.getEdits()) {
            if (edit.getType() == Edit.Type.EMPTY) {
                continue;
            }
            content.addCommon(edit.getBeginA());
            checkState(content.nextA == edit.getBeginA(), "nextA = %s; want %s", content.nextA, edit.getBeginA());
            checkState(content.nextB == edit.getBeginB(), "nextB = %s; want %s", content.nextB, edit.getBeginB());
            switch(edit.getType()) {
                case DELETE:
                case INSERT:
                case REPLACE:
                    List<Edit> internalEdit = edit instanceof ReplaceEdit ? ((ReplaceEdit) edit).getInternalEdits() : null;
                    content.addDiff(edit.getEndA(), edit.getEndB(), internalEdit);
                    break;
                case EMPTY:
                default:
                    throw new IllegalStateException();
            }
        }
        content.addCommon(ps.getA().size());
        ProjectState state = projectCache.get(resource.getRevision().getChange().getProject());
        DiffInfo result = new DiffInfo();
        // TODO referring to the parent commit by refs/changes/12/60012/1^1
        // will likely not work for inline edits
        String revA = basePatchSet != null ? basePatchSet.getRefName() : resource.getRevision().getPatchSet().getRefName() + "^1";
        String revB = resource.getRevision().getEdit().isPresent() ? resource.getRevision().getEdit().get().getRefName() : resource.getRevision().getPatchSet().getRefName();
        List<DiffWebLinkInfo> links = webLinks.getDiffLinks(state.getProject().getName(), resource.getPatchKey().getParentKey().getParentKey().get(), basePatchSet != null ? basePatchSet.getId().get() : null, revA, MoreObjects.firstNonNull(ps.getOldName(), ps.getNewName()), resource.getPatchKey().getParentKey().get(), revB, ps.getNewName());
        result.webLinks = links.isEmpty() ? null : links;
        if (!webLinksOnly) {
            if (ps.isBinary()) {
                result.binary = true;
            }
            if (ps.getDisplayMethodA() != DisplayMethod.NONE) {
                result.metaA = new FileMeta();
                result.metaA.name = MoreObjects.firstNonNull(ps.getOldName(), ps.getNewName());
                result.metaA.contentType = FileContentUtil.resolveContentType(state, result.metaA.name, ps.getFileModeA(), ps.getMimeTypeA());
                result.metaA.lines = ps.getA().size();
                result.metaA.webLinks = getFileWebLinks(state.getProject(), revA, result.metaA.name);
                result.metaA.commitId = content.commitIdA;
            }
            if (ps.getDisplayMethodB() != DisplayMethod.NONE) {
                result.metaB = new FileMeta();
                result.metaB.name = ps.getNewName();
                result.metaB.contentType = FileContentUtil.resolveContentType(state, result.metaB.name, ps.getFileModeB(), ps.getMimeTypeB());
                result.metaB.lines = ps.getB().size();
                result.metaB.webLinks = getFileWebLinks(state.getProject(), revB, result.metaB.name);
                result.metaB.commitId = content.commitIdB;
            }
            if (intraline) {
                if (ps.hasIntralineTimeout()) {
                    result.intralineStatus = IntraLineStatus.TIMEOUT;
                } else if (ps.hasIntralineFailure()) {
                    result.intralineStatus = IntraLineStatus.FAILURE;
                } else {
                    result.intralineStatus = IntraLineStatus.OK;
                }
            }
            result.changeType = CHANGE_TYPE.get(ps.getChangeType());
            if (result.changeType == null) {
                throw new IllegalStateException("unknown change type: " + ps.getChangeType());
            }
            if (ps.getPatchHeader().size() > 0) {
                result.diffHeader = ps.getPatchHeader();
            }
            result.content = content.lines;
        }
        Response<DiffInfo> r = Response.ok(result);
        if (resource.isCacheable()) {
            r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
        }
        return r;
    } catch (NoSuchChangeException e) {
        throw new ResourceNotFoundException(e.getMessage(), e);
    } catch (LargeObjectException e) {
        throw new ResourceConflictException(e.getMessage(), e);
    }
}
Also used : PatchScript(com.google.gerrit.common.data.PatchScript) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ReplaceEdit(org.eclipse.jgit.diff.ReplaceEdit) Edit(org.eclipse.jgit.diff.Edit) IdString(com.google.gerrit.extensions.restapi.IdString) LargeObjectException(com.google.gerrit.server.git.LargeObjectException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) DiffWebLinkInfo(com.google.gerrit.extensions.common.DiffWebLinkInfo) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) PatchScriptFactory(com.google.gerrit.server.patch.PatchScriptFactory) SparseFileContent(com.google.gerrit.prettify.common.SparseFileContent) ReplaceEdit(org.eclipse.jgit.diff.ReplaceEdit) ProjectState(com.google.gerrit.server.project.ProjectState) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) FileMeta(com.google.gerrit.extensions.common.DiffInfo.FileMeta) DiffInfo(com.google.gerrit.extensions.common.DiffInfo)

Example 15 with NoSuchChangeException

use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.

the class ChangeNotes method onLoad.

@Override
protected void onLoad(LoadHandle handle) throws NoSuchChangeException, IOException, ConfigInvalidException {
    ObjectId rev = handle.id();
    if (rev == null) {
        if (args.migration.readChanges() && PrimaryStorage.of(change) == PrimaryStorage.NOTE_DB && shouldExist) {
            throw new NoSuchChangeException(getChangeId());
        }
        loadDefaults();
        return;
    }
    ChangeNotesCache.Value v = args.cache.get().get(getProjectName(), getChangeId(), rev, handle.walk());
    state = v.state();
    state.copyColumnsTo(change);
    revisionNoteMap = v.revisionNoteMap();
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ObjectId(org.eclipse.jgit.lib.ObjectId)

Aggregations

NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)24 Change (com.google.gerrit.reviewdb.client.Change)16 OrmException (com.google.gwtorm.server.OrmException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 IOException (java.io.IOException)7 Repository (org.eclipse.jgit.lib.Repository)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)4 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)4 ChangeControl (com.google.gerrit.server.project.ChangeControl)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 Timer1 (com.google.gerrit.metrics.Timer1)2 LargeObjectException (com.google.gerrit.server.git.LargeObjectException)2 NoteDbUpdateManager (com.google.gerrit.server.notedb.NoteDbUpdateManager)2 ChangeRebuilder (com.google.gerrit.server.notedb.rebuild.ChangeRebuilder)2 InvalidChangeOperationException (com.google.gerrit.server.project.InvalidChangeOperationException)2 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)2