Search in sources :

Example 21 with NoSuchChangeException

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

the class ChangeNotes method openHandle.

@Override
protected LoadHandle openHandle(Repository repo) throws NoSuchChangeException, IOException {
    if (autoRebuild) {
        NoteDbChangeState state = NoteDbChangeState.parse(change);
        ObjectId id = readRef(repo);
        if (id == null) {
            if (state == null) {
                return super.openHandle(repo, id);
            } else if (shouldExist) {
                throw new NoSuchChangeException(getChangeId());
            }
        }
        RefCache refs = this.refs != null ? this.refs : new RepoRefCache(repo);
        if (!NoteDbChangeState.isChangeUpToDate(state, refs, getChangeId())) {
            return rebuildAndOpen(repo, id);
        }
    }
    return super.openHandle(repo);
}
Also used : RepoRefCache(com.google.gerrit.server.git.RepoRefCache) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) ObjectId(org.eclipse.jgit.lib.ObjectId) RepoRefCache(com.google.gerrit.server.git.RepoRefCache) RefCache(com.google.gerrit.server.git.RefCache)

Example 22 with NoSuchChangeException

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

the class ChangeRebuilderImpl method rebuild.

private Result rebuild(ReviewDb db, Change.Id changeId, boolean checkReadOnly) throws IOException, OrmException {
    db = ReviewDbUtil.unwrapDb(db);
    // Read change just to get project; this instance is then discarded so we
    // can read a consistent ChangeBundle inside a transaction.
    Change change = db.changes().get(changeId);
    if (change == null) {
        throw new NoSuchChangeException(changeId);
    }
    try (NoteDbUpdateManager manager = updateManagerFactory.create(change.getProject())) {
        buildUpdates(manager, bundleReader.fromReviewDb(db, changeId));
        return execute(db, changeId, manager, checkReadOnly);
    }
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) NoteDbUpdateManager(com.google.gerrit.server.notedb.NoteDbUpdateManager) Change(com.google.gerrit.reviewdb.client.Change)

Example 23 with NoSuchChangeException

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

the class ChangeRebuilderImpl method stage.

@Override
public NoteDbUpdateManager stage(ReviewDb db, Change.Id changeId) throws IOException, OrmException {
    db = ReviewDbUtil.unwrapDb(db);
    Change change = checkNoteDbState(ChangeNotes.readOneReviewDbChange(db, changeId));
    if (change == null) {
        throw new NoSuchChangeException(changeId);
    }
    NoteDbUpdateManager manager = updateManagerFactory.create(change.getProject());
    buildUpdates(manager, bundleReader.fromReviewDb(db, changeId));
    manager.stage();
    return manager;
}
Also used : NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) NoteDbUpdateManager(com.google.gerrit.server.notedb.NoteDbUpdateManager) Change(com.google.gerrit.reviewdb.client.Change)

Example 24 with NoSuchChangeException

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

the class PatchScriptFactory method call.

@Override
public PatchScript call() throws OrmException, LargeObjectException, AuthException, InvalidChangeOperationException, IOException {
    if (parentNum < 0) {
        validatePatchSetId(psa);
    }
    validatePatchSetId(psb);
    change = control.getChange();
    project = change.getProject();
    PatchSet psEntityA = psa != null ? psUtil.get(db, control.getNotes(), psa) : null;
    PatchSet psEntityB = psb.get() == 0 ? new PatchSet(psb) : psUtil.get(db, control.getNotes(), psb);
    if ((psEntityA != null && !control.isPatchVisible(psEntityA, db)) || (psEntityB != null && !control.isPatchVisible(psEntityB, db))) {
        throw new NoSuchChangeException(changeId);
    }
    try (Repository git = repoManager.openRepository(project)) {
        bId = toObjectId(psEntityB);
        if (parentNum < 0) {
            aId = psEntityA != null ? toObjectId(psEntityA) : null;
        }
        try {
            final PatchList list = listFor(keyFor(diffPrefs.ignoreWhitespace));
            final PatchScriptBuilder b = newBuilder(list, git);
            final PatchListEntry content = list.get(fileName);
            loadCommentsAndHistory(control.getNotes(), content.getChangeType(), content.getOldName(), content.getNewName());
            return b.toPatchScript(content, comments, history);
        } catch (PatchListNotAvailableException e) {
            throw new NoSuchChangeException(changeId, e);
        } catch (IOException e) {
            log.error("File content unavailable", e);
            throw new NoSuchChangeException(changeId, e);
        } catch (org.eclipse.jgit.errors.LargeObjectException err) {
            throw new LargeObjectException("File content is too large", err);
        }
    } catch (RepositoryNotFoundException e) {
        log.error("Repository " + project + " not found", e);
        throw new NoSuchChangeException(changeId, e);
    } catch (IOException e) {
        log.error("Cannot open repository " + project, e);
        throw new NoSuchChangeException(changeId, e);
    }
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) 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)

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