Search in sources :

Example 1 with RepoRefCache

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);
    }
}
Also used : RepoRefCache(com.google.gerrit.server.git.RepoRefCache) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.reviewdb.client.Change)

Example 2 with RepoRefCache

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));
}
Also used : RepoRefCache(com.google.gerrit.server.git.RepoRefCache) Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.reviewdb.client.Change) NoteDbChangeState(com.google.gerrit.server.notedb.NoteDbChangeState)

Example 3 with RepoRefCache

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);
    }
}
Also used : RepoRefCache(com.google.gerrit.server.git.RepoRefCache) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.reviewdb.client.Change) NoteDbChangeState(com.google.gerrit.server.notedb.NoteDbChangeState)

Example 4 with RepoRefCache

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;
}
Also used : RepoRefCache(com.google.gerrit.server.git.RepoRefCache) Repository(org.eclipse.jgit.lib.Repository)

Example 5 with RepoRefCache

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

Aggregations

RepoRefCache (com.google.gerrit.server.git.RepoRefCache)5 Repository (org.eclipse.jgit.lib.Repository)4 Change (com.google.gerrit.reviewdb.client.Change)3 NoteDbChangeState (com.google.gerrit.server.notedb.NoteDbChangeState)2 TestRepository (org.eclipse.jgit.junit.TestRepository)2 RefCache (com.google.gerrit.server.git.RefCache)1 NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1