Search in sources :

Example 91 with Repository

use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.

the class SchemaCreatorTest method getLabelTypes.

private LabelTypes getLabelTypes() throws Exception {
    db.create();
    ProjectConfig c = new ProjectConfig(allProjects);
    try (Repository repo = repoManager.openRepository(allProjects)) {
        c.load(repo);
        return new LabelTypes(ImmutableList.copyOf(c.getLabelSections().values()));
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) LabelTypes(com.google.gerrit.common.data.LabelTypes)

Example 92 with Repository

use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.

the class FixReplacementInterpreter method toTreeModifications.

/**
   * Transforms the given {@code FixReplacement}s into {@code TreeModification}s.
   *
   * @param repository the affected Git repository
   * @param projectState the affected project
   * @param patchSetCommitId the patch set which should be modified
   * @param fixReplacements the replacements which should be applied
   * @return a list of {@code TreeModification}s representing the given replacements
   * @throws ResourceNotFoundException if a file to which one of the replacements refers doesn't
   *     exist
   * @throws ResourceConflictException if the replacements can't be transformed into {@code
   *     TreeModification}s
   */
public List<TreeModification> toTreeModifications(Repository repository, ProjectState projectState, ObjectId patchSetCommitId, List<FixReplacement> fixReplacements) throws ResourceNotFoundException, IOException, ResourceConflictException {
    checkNotNull(fixReplacements, "Fix replacements must not be null");
    Map<String, List<FixReplacement>> fixReplacementsPerFilePath = fixReplacements.stream().collect(Collectors.groupingBy(fixReplacement -> fixReplacement.path));
    List<TreeModification> treeModifications = new ArrayList<>();
    for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
        TreeModification treeModification = toTreeModification(repository, projectState, patchSetCommitId, entry.getKey(), entry.getValue());
        treeModifications.add(treeModification);
    }
    return treeModifications;
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) Inject(com.google.inject.Inject) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RawInputUtil(com.google.gerrit.common.RawInputUtil) ChangeFileContentModification(com.google.gerrit.server.edit.tree.ChangeFileContentModification) ProjectState(com.google.gerrit.server.project.ProjectState) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ObjectId(org.eclipse.jgit.lib.ObjectId) Comment(com.google.gerrit.reviewdb.client.Comment) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) List(java.util.List) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) FileContentUtil(com.google.gerrit.server.change.FileContentUtil) Map(java.util.Map) Comparator(java.util.Comparator) Repository(org.eclipse.jgit.lib.Repository) Singleton(com.google.inject.Singleton) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) Map(java.util.Map)

Example 93 with Repository

use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.

the class ChangeEditUtil method delete.

/**
   * Delete change edit.
   *
   * @param edit change edit to delete
   * @throws IOException
   * @throws OrmException
   */
public void delete(ChangeEdit edit) throws IOException, OrmException {
    Change change = edit.getChange();
    try (Repository repo = gitManager.openRepository(change.getProject())) {
        deleteRef(repo, edit);
    }
    indexer.index(db.get(), change);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.reviewdb.client.Change)

Example 94 with Repository

use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.

the class NoteDbUpdateManager method openRepo.

private OpenRepo openRepo(Project.NameKey p) throws IOException {
    // Closed by OpenRepo#close.
    Repository repo = repoManager.openRepository(p);
    // Closed by OpenRepo#close.
    ObjectInserter ins = repo.newObjectInserter();
    // Not closed by OpenRepo#close.
    ObjectReader reader = ins.newReader();
    try (RevWalk rw = new RevWalk(reader)) {
        // Doesn't escape OpenRepo constructor.
        return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true) {

            @Override
            public void close() {
                reader.close();
                super.close();
            }
        };
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ChainedReceiveCommands(com.google.gerrit.server.update.ChainedReceiveCommands) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 95 with Repository

use of org.eclipse.jgit.lib.Repository in project gerrit by GerritCodeReview.

the class PrimaryStorageMigrator method setPrimaryStorageReviewDb.

private void setPrimaryStorageReviewDb(Change.Id id, ObjectId newMetaId) throws OrmException, IOException {
    ImmutableMap.Builder<Account.Id, ObjectId> draftIds = ImmutableMap.builder();
    try (Repository repo = repoManager.openRepository(allUsers)) {
        for (Ref draftRef : repo.getRefDatabase().getRefs(RefNames.refsDraftCommentsPrefix(id)).values()) {
            Account.Id accountId = Account.Id.fromRef(draftRef.getName());
            if (accountId != null) {
                draftIds.put(accountId, draftRef.getObjectId().copy());
            }
        }
    }
    NoteDbChangeState newState = new NoteDbChangeState(id, PrimaryStorage.REVIEW_DB, Optional.of(RefState.create(newMetaId, draftIds.build())), Optional.empty());
    db().changes().atomicUpdate(id, new AtomicUpdate<Change>() {

        @Override
        public Change update(Change change) {
            if (PrimaryStorage.of(change) != PrimaryStorage.NOTE_DB) {
                throw new OrmRuntimeException("change " + id + " is not NoteDb primary: " + change.getNoteDbState());
            }
            change.setNoteDbState(newState.toString());
            return change;
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) OrmRuntimeException(com.google.gwtorm.server.OrmRuntimeException) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.reviewdb.client.Change) ImmutableMap(com.google.common.collect.ImmutableMap) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId)

Aggregations

Repository (org.eclipse.jgit.lib.Repository)326 IOException (java.io.IOException)103 RevWalk (org.eclipse.jgit.revwalk.RevWalk)102 Test (org.junit.Test)81 RevCommit (org.eclipse.jgit.revwalk.RevCommit)76 ObjectId (org.eclipse.jgit.lib.ObjectId)72 File (java.io.File)43 TestRepository (org.eclipse.jgit.junit.TestRepository)40 Change (com.google.gerrit.reviewdb.client.Change)39 OrmException (com.google.gwtorm.server.OrmException)39 Ref (org.eclipse.jgit.lib.Ref)35 Project (com.google.gerrit.reviewdb.client.Project)32 ArrayList (java.util.ArrayList)31 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)27 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)26 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 Map (java.util.Map)23 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)23 RepositoryModel (com.gitblit.models.RepositoryModel)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20