Search in sources :

Example 1 with GitRepositoryManager

use of com.google.gerrit.server.git.GitRepositoryManager in project gerrit by GerritCodeReview.

the class NoteDbSchemaVersionManagerTest method setUp.

@Before
public void setUp() throws Exception {
    AllProjectsName allProjectsName = new AllProjectsName("The-Projects");
    GitRepositoryManager repoManager = new InMemoryRepositoryManager();
    tr = new TestRepository<>(repoManager.createRepository(allProjectsName));
    manager = new NoteDbSchemaVersionManager(allProjectsName, repoManager);
}
Also used : AllProjectsName(com.google.gerrit.server.config.AllProjectsName) InMemoryRepositoryManager(com.google.gerrit.testing.InMemoryRepositoryManager) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Before(org.junit.Before)

Example 2 with GitRepositoryManager

use of com.google.gerrit.server.git.GitRepositoryManager in project gerrit by GerritCodeReview.

the class Schema_182 method upgrade.

@Override
public void upgrade(Arguments args, UpdateUI ui) throws Exception {
    AllUsersName allUsers = args.allUsers;
    GitRepositoryManager gitRepoManager = args.repoManager;
    DeleteZombieCommentsRefs cleanup = new DeleteZombieCommentsRefs(allUsers, gitRepoManager, 100, ui::message);
    cleanup.execute();
}
Also used : DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) AllUsersName(com.google.gerrit.server.config.AllUsersName)

Example 3 with GitRepositoryManager

use of com.google.gerrit.server.git.GitRepositoryManager in project gerrit by GerritCodeReview.

the class TestChanges method newUpdate.

public static ChangeUpdate newUpdate(Injector injector, Change c, CurrentUser user, boolean shouldExist) throws Exception {
    injector = injector.createChildInjector(new FactoryModule() {

        @Override
        public void configure() {
            bind(CurrentUser.class).toInstance(user);
        }
    });
    ChangeUpdate update = injector.getInstance(ChangeUpdate.Factory.class).create(new ChangeNotes(injector.getInstance(AbstractChangeNotes.Args.class), c, shouldExist, null).load(), user, TimeUtil.now(), Ordering.natural());
    ChangeNotes notes = update.getNotes();
    boolean hasPatchSets = notes.getPatchSets() != null && !notes.getPatchSets().isEmpty();
    if (hasPatchSets) {
        return update;
    }
    // Change doesn't exist yet. NoteDb requires that there be a commit for the
    // first patch set, so create one.
    GitRepositoryManager repoManager = injector.getInstance(GitRepositoryManager.class);
    try (Repository repo = repoManager.openRepository(c.getProject());
        TestRepository<Repository> tr = new TestRepository<>(repo)) {
        PersonIdent ident = user.asIdentifiedUser().newCommitterIdent(update.getWhen(), TimeZone.getDefault());
        TestRepository<Repository>.CommitBuilder cb = tr.commit().author(ident).committer(ident).message(firstNonNull(c.getSubject(), "Test change"));
        Ref parent = repo.exactRef(c.getDest().branch());
        if (parent != null) {
            cb.parent(tr.getRevWalk().parseCommit(parent.getObjectId()));
        }
        update.setBranch(c.getDest().branch());
        update.setChangeId(c.getKey().get());
        update.setCommit(tr.getRevWalk(), cb.create());
        return update;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) CurrentUser(com.google.gerrit.server.CurrentUser) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 4 with GitRepositoryManager

use of com.google.gerrit.server.git.GitRepositoryManager in project gerrit by GerritCodeReview.

the class TestChanges method newUpdate.

public static ChangeUpdate newUpdate(Injector injector, Change c, final CurrentUser user) throws Exception {
    injector = injector.createChildInjector(new FactoryModule() {

        @Override
        public void configure() {
            bind(CurrentUser.class).toInstance(user);
        }
    });
    ChangeUpdate update = injector.getInstance(ChangeUpdate.Factory.class).create(stubChangeControl(injector.getInstance(AbstractChangeNotes.Args.class), c, user), TimeUtil.nowTs(), Ordering.<String>natural());
    ChangeNotes notes = update.getNotes();
    boolean hasPatchSets = notes.getPatchSets() != null && !notes.getPatchSets().isEmpty();
    NotesMigration migration = injector.getInstance(NotesMigration.class);
    if (hasPatchSets || !migration.readChanges()) {
        return update;
    }
    // Change doesn't exist yet. NoteDb requires that there be a commit for the
    // first patch set, so create one.
    GitRepositoryManager repoManager = injector.getInstance(GitRepositoryManager.class);
    try (Repository repo = repoManager.openRepository(c.getProject())) {
        TestRepository<Repository> tr = new TestRepository<>(repo);
        PersonIdent ident = user.asIdentifiedUser().newCommitterIdent(update.getWhen(), TimeZone.getDefault());
        TestRepository<Repository>.CommitBuilder<Repository> cb = tr.commit().author(ident).committer(ident).message(firstNonNull(c.getSubject(), "Test change"));
        Ref parent = repo.exactRef(c.getDest().get());
        if (parent != null) {
            cb.parent(tr.getRevWalk().parseCommit(parent.getObjectId()));
        }
        update.setBranch(c.getDest().get());
        update.setChangeId(c.getKey().get());
        update.setCommit(tr.getRevWalk(), cb.create());
        return update;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) CurrentUser(com.google.gerrit.server.CurrentUser) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 5 with GitRepositoryManager

use of com.google.gerrit.server.git.GitRepositoryManager in project gerrit by GerritCodeReview.

the class ChangeExternalIdCaseSensitivityIT method getExternalIdNotes.

private static ExternalIdNotes getExternalIdNotes(ServerContext ctx, Project.NameKey allUsers) throws Exception {
    GitRepositoryManager repoManager = ctx.getInjector().getInstance(GitRepositoryManager.class);
    ExternalIdNotes.FactoryNoReindex extIdNotesFactory = ctx.getInjector().getInstance(ExternalIdNotes.FactoryNoReindex.class);
    return extIdNotesFactory.load(repoManager.openRepository(allUsers));
}
Also used : ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager)

Aggregations

GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)6 FactoryModule (com.google.gerrit.extensions.config.FactoryModule)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 AllProjectsName (com.google.gerrit.server.config.AllProjectsName)2 AbstractChangeNotes (com.google.gerrit.server.notedb.AbstractChangeNotes)2 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)2 ChangeUpdate (com.google.gerrit.server.notedb.ChangeUpdate)2 InMemoryRepositoryManager (com.google.gerrit.testing.InMemoryRepositoryManager)2 TestRepository (org.eclipse.jgit.junit.TestRepository)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 Ref (org.eclipse.jgit.lib.Ref)2 Repository (org.eclipse.jgit.lib.Repository)2 Before (org.junit.Before)2 ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 SitePaths (com.google.gerrit.server.config.SitePaths)1 DeleteZombieCommentsRefs (com.google.gerrit.server.notedb.DeleteZombieCommentsRefs)1 NotesMigration (com.google.gerrit.server.notedb.NotesMigration)1