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);
}
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);
}
}
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;
}
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);
}
}
Aggregations