Search in sources :

Example 26 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class ConvertRefStorage method run.

@Override
public void run() throws Exception {
    enableGracefulStop();
    Project.NameKey projectName = projectState.getNameKey();
    try (Repository repo = repoManager.openRepository(projectName)) {
        if (repo instanceof DelegateRepository) {
            ((DelegateRepository) repo).convertRefStorage(storageFormat.name(), writeLogs, backup);
        } else {
            checkState(repo instanceof FileRepository, "Repository is not an instance of FileRepository!");
            ((FileRepository) repo).convertRefStorage(storageFormat.name(), writeLogs, backup);
        }
    } catch (RepositoryNotFoundException e) {
        throw die("'" + projectName + "': not a git archive", e);
    } catch (IOException e) {
        throw die("Error converting: '" + projectName + "': " + e.getMessage(), e);
    }
}
Also used : Project(com.google.gerrit.entities.Project) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) DelegateRepository(com.google.gerrit.server.git.DelegateRepository) Repository(org.eclipse.jgit.lib.Repository) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) DelegateRepository(com.google.gerrit.server.git.DelegateRepository)

Example 27 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class CommitRewriter method newPackInserter.

private static ObjectInserter newPackInserter(Repository repo) {
    if (!(repo instanceof FileRepository)) {
        return repo.newObjectInserter();
    }
    PackInserter ins = ((FileRepository) repo).getObjectDatabase().newPackInserter();
    ins.checkExisting(false);
    return ins;
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) PackInserter(org.eclipse.jgit.internal.storage.file.PackInserter)

Example 28 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class GroupsOnInit method getExistingGroup.

/**
 * Returns the {@code AccountGroup} for the specified {@code GroupReference}.
 *
 * @param groupReference the {@code GroupReference} of the group
 * @return the {@code InternalGroup} represented by the {@code GroupReference}
 * @throws IOException if an error occurs while reading from NoteDb
 * @throws ConfigInvalidException if the data in NoteDb is in an incorrect format
 * @throws NoSuchGroupException if a group with such a name doesn't exist
 */
public InternalGroup getExistingGroup(GroupReference groupReference) throws NoSuchGroupException, IOException, ConfigInvalidException {
    File allUsersRepoPath = getPathToAllUsersRepository();
    if (allUsersRepoPath != null) {
        try (Repository allUsersRepo = new FileRepository(allUsersRepoPath)) {
            AccountGroup.UUID groupUuid = groupReference.getUUID();
            GroupConfig groupConfig = GroupConfig.loadForGroup(allUsers, allUsersRepo, groupUuid);
            return groupConfig.getLoadedGroup().orElseThrow(() -> new NoSuchGroupException(groupReference.getUUID()));
        }
    }
    throw new NoSuchGroupException(groupReference.getUUID());
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupConfig(com.google.gerrit.server.group.db.GroupConfig) File(java.io.File) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 29 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class ExternalIdsOnInit method insert.

public synchronized void insert(String commitMessage, Collection<ExternalId> extIds) throws IOException, ConfigInvalidException {
    File path = getPath();
    if (path != null) {
        try (Repository allUsersRepo = new FileRepository(path)) {
            ExternalIdNotes extIdNotes = ExternalIdNotes.load(allUsers, allUsersRepo, externalIdFactory, authConfig.isUserNameCaseInsensitiveMigrationMode());
            extIdNotes.insert(extIds);
            try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsers, allUsersRepo)) {
                PersonIdent serverIdent = new GerritPersonIdentProvider(flags.cfg).get();
                metaDataUpdate.getCommitBuilder().setAuthor(serverIdent);
                metaDataUpdate.getCommitBuilder().setCommitter(serverIdent);
                metaDataUpdate.getCommitBuilder().setMessage(commitMessage);
                extIdNotes.commit(metaDataUpdate);
            }
        }
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) File(java.io.File) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 30 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class AllProjectsConfigTest method noBaseConfig.

@Test
public void noBaseConfig() throws Exception {
    assertThat(getConfig().getString("foo", null, "bar")).isNull();
    try (Repository repo = new FileRepository(allProjectsRepoFile);
        TestRepository<Repository> tr = new TestRepository<>(repo)) {
        tr.branch("refs/meta/config").commit().add("project.config", "[foo]\nbar = baz").create();
    }
    assertThat(getConfig().getString("foo", null, "bar")).isEqualTo("baz");
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) Test(org.junit.Test)

Aggregations

FileRepository (org.eclipse.jgit.internal.storage.file.FileRepository)34 Repository (org.eclipse.jgit.lib.Repository)29 Git (org.eclipse.jgit.api.Git)18 File (java.io.File)16 TestRepository (org.eclipse.jgit.junit.TestRepository)6 IOException (java.io.IOException)5 Test (org.junit.Test)5 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 GerritPersonIdentProvider (com.google.gerrit.server.GerritPersonIdentProvider)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 FileBasedAllProjectsConfigProvider (com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider)2 SitePaths (com.google.gerrit.server.config.SitePaths)2 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2