Search in sources :

Example 1 with IntBlob

use of com.google.gerrit.server.notedb.IntBlob in project gerrit by GerritCodeReview.

the class NoteDbSchemaVersionManager method increment.

public void increment(int expectedOldVersion) throws IOException {
    try (Repository repo = repoManager.openRepository(allProjectsName);
        RevWalk rw = new RevWalk(repo)) {
        Optional<IntBlob> old = IntBlob.parse(repo, REFS_VERSION, rw);
        if (old.isPresent() && old.get().value() != expectedOldVersion) {
            throw new StorageException(String.format("Expected old version %d for %s, found %d", expectedOldVersion, REFS_VERSION, old.get().value()));
        }
        IntBlob.store(repo, rw, allProjectsName, REFS_VERSION, old.map(IntBlob::id).orElse(ObjectId.zeroId()), expectedOldVersion + 1, GitReferenceUpdated.DISABLED);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IntBlob(com.google.gerrit.server.notedb.IntBlob) RevWalk(org.eclipse.jgit.revwalk.RevWalk) StorageException(com.google.gerrit.exceptions.StorageException)

Example 2 with IntBlob

use of com.google.gerrit.server.notedb.IntBlob in project gerrit by GerritCodeReview.

the class NoteDbSchemaVersionManager method init.

public void init() throws IOException {
    try (Repository repo = repoManager.openRepository(allProjectsName);
        RevWalk rw = new RevWalk(repo)) {
        Optional<IntBlob> old = IntBlob.parse(repo, REFS_VERSION, rw);
        if (old.isPresent()) {
            throw new StorageException(String.format("Expected no old version for %s, found %s", REFS_VERSION, old.get().value()));
        }
        IntBlob.store(repo, rw, allProjectsName, REFS_VERSION, old.map(IntBlob::id).orElse(ObjectId.zeroId()), NoteDbSchemaVersions.LATEST, GitReferenceUpdated.DISABLED);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IntBlob(com.google.gerrit.server.notedb.IntBlob) RevWalk(org.eclipse.jgit.revwalk.RevWalk) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)2 IntBlob (com.google.gerrit.server.notedb.IntBlob)2 Repository (org.eclipse.jgit.lib.Repository)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2