use of com.google.gerrit.server.git.RepoRefCache in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method assertChangeUpToDate.
private void assertChangeUpToDate(boolean expected, Change.Id id) throws Exception {
try (Repository repo = repoManager.openRepository(project)) {
Change c = getUnwrappedDb().changes().get(id);
assertThat(c).isNotNull();
assertThat(c.getNoteDbState()).isNotNull();
assertThat(NoteDbChangeState.parse(c).isChangeUpToDate(new RepoRefCache(repo))).isEqualTo(expected);
}
}
use of com.google.gerrit.server.git.RepoRefCache in project gerrit by GerritCodeReview.
the class NoteDbPrimaryIT method setNoteDbPrimary.
private void setNoteDbPrimary(Change.Id id) throws Exception {
Change c = db.changes().get(id);
assertThat(c).named("change " + id).isNotNull();
NoteDbChangeState state = NoteDbChangeState.parse(c);
assertThat(state.getPrimaryStorage()).named("storage of " + id).isEqualTo(REVIEW_DB);
try (Repository changeRepo = repoManager.openRepository(c.getProject());
Repository allUsersRepo = repoManager.openRepository(allUsers)) {
assertThat(state.isUpToDate(new RepoRefCache(changeRepo), new RepoRefCache(allUsersRepo))).named("change " + id + " up to date").isTrue();
}
c.setNoteDbState(NoteDbChangeState.NOTE_DB_PRIMARY_STATE);
db.changes().update(Collections.singleton(c));
}
use of com.google.gerrit.server.git.RepoRefCache in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method assertDraftsUpToDate.
private void assertDraftsUpToDate(boolean expected, Change.Id changeId, TestAccount account) throws Exception {
try (Repository repo = repoManager.openRepository(allUsers)) {
Change c = getUnwrappedDb().changes().get(changeId);
assertThat(c).isNotNull();
assertThat(c.getNoteDbState()).isNotNull();
NoteDbChangeState state = NoteDbChangeState.parse(c);
assertThat(state.areDraftsUpToDate(new RepoRefCache(repo), account.getId())).isEqualTo(expected);
}
}
use of com.google.gerrit.server.git.RepoRefCache in project gerrit by GerritCodeReview.
the class PrimaryStorageMigrator method ensureRebuilt.
private NoteDbChangeState ensureRebuilt(Project.NameKey project, Change.Id id, NoteDbChangeState readOnlyState) throws IOException, OrmException, RepositoryNotFoundException {
try (Repository changeRepo = repoManager.openRepository(project);
Repository allUsersRepo = repoManager.openRepository(allUsers)) {
if (!readOnlyState.isUpToDate(new RepoRefCache(changeRepo), new RepoRefCache(allUsersRepo))) {
NoteDbUpdateManager.Result r = rebuilder.rebuildEvenIfReadOnly(db(), id);
checkState(r.newState().getReadOnlyUntil().equals(readOnlyState.getReadOnlyUntil()), "state after rebuilding has different read-only lease: %s != %s", r.newState(), readOnlyState);
readOnlyState = r.newState();
}
}
return readOnlyState;
}
use of com.google.gerrit.server.git.RepoRefCache 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);
}
Aggregations