Search in sources :

Example 61 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class ConflictsPredicate method listFiles.

public static List<String> listFiles(Change c, Arguments args, ChangeDataCache changeDataCache) throws OrmException {
    try (Repository repo = args.repoManager.openRepository(c.getProject());
        RevWalk rw = new RevWalk(repo)) {
        RevCommit ps = rw.parseCommit(changeDataCache.getTestAgainst());
        if (ps.getParentCount() > 1) {
            String dest = c.getDest().get();
            Ref destBranch = repo.getRefDatabase().getRef(dest);
            destBranch.getObjectId();
            rw.setRevFilter(RevFilter.MERGE_BASE);
            rw.markStart(rw.parseCommit(destBranch.getObjectId()));
            rw.markStart(ps);
            RevCommit base = rw.next();
            // TODO(zivkov): handle the case with multiple merge bases
            List<String> files = new ArrayList<>();
            try (TreeWalk tw = new TreeWalk(repo)) {
                if (base != null) {
                    tw.setFilter(TreeFilter.ANY_DIFF);
                    tw.addTree(base.getTree());
                }
                tw.addTree(ps.getTree());
                tw.setRecursive(true);
                while (tw.next()) {
                    files.add(tw.getPathString());
                }
            }
            return files;
        }
        return args.changeDataFactory.create(args.db.get(), c).currentFilePaths();
    } catch (IOException e) {
        throw new OrmException(e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) OrmException(com.google.gwtorm.server.OrmException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CodeReviewRevWalk(com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 62 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method newPatchSet.

protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
    // Add a new file so the patch set is not a trivial rebase, to avoid default
    // Code-Review label copying.
    int n = c.currentPatchSetId().get() + 1;
    RevCommit commit = repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
    ChangeControl ctl = changeControlFactory.controlFor(db, c, user);
    PatchSetInserter inserter = patchSetFactory.create(ctl, new PatchSet.Id(c.getId(), n), commit).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setValidate(false);
    try (BatchUpdate bu = updateFactory.create(db, c.getProject(), user, TimeUtil.nowTs());
        ObjectInserter oi = repo.getRepository().newObjectInserter();
        ObjectReader reader = oi.newReader();
        RevWalk rw = new RevWalk(reader)) {
        bu.setRepository(repo.getRepository(), rw, oi);
        bu.addOp(c.getId(), inserter);
        bu.execute();
    }
    return inserter.getChange();
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) ChangeControl(com.google.gerrit.server.project.ChangeControl) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 63 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class ProjectControlTest method canReadCommitIfReachableFromVisibleRef.

@Test
public void canReadCommitIfReachableFromVisibleRef() throws Exception {
    allow(project, READ, REGISTERED_USERS, "refs/heads/branch1");
    deny(project, READ, REGISTERED_USERS, "refs/heads/branch2");
    RevCommit parent1 = repo.commit().create();
    repo.branch("branch1").commit().parent(parent1).create();
    RevCommit parent2 = repo.commit().create();
    repo.branch("branch2").commit().parent(parent2).create();
    ProjectControl pc = newProjectControl();
    RevWalk rw = repo.getRevWalk();
    Repository r = repo.getRepository();
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
    assertFalse(pc.canReadCommit(db, r, rw.parseCommit(parent2)));
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 64 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class ProjectControlTest method canReadAfterRollbackWithAllRefsVisible.

@Test
public void canReadAfterRollbackWithAllRefsVisible() throws Exception {
    allow(project, READ, REGISTERED_USERS, "refs/*");
    RevCommit parent1 = repo.commit().create();
    ObjectId id1 = repo.branch("branch1").commit().parent(parent1).create();
    ProjectControl pc = newProjectControl();
    RevWalk rw = repo.getRevWalk();
    Repository r = repo.getRepository();
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
    repo.branch("branch1").update(parent1);
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
    assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id1)));
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 65 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project gerrit by GerritCodeReview.

the class ProjectControlTest method cannotReadAfterRollbackWithRestrictedRead.

@Test
public void cannotReadAfterRollbackWithRestrictedRead() throws Exception {
    allow(project, READ, REGISTERED_USERS, "refs/heads/branch1");
    RevCommit parent1 = repo.commit().create();
    ObjectId id1 = repo.branch("branch1").commit().parent(parent1).create();
    ProjectControl pc = newProjectControl();
    RevWalk rw = repo.getRevWalk();
    Repository r = repo.getRepository();
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
    repo.branch("branch1").update(parent1);
    assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
    assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id1)));
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

RevCommit (org.eclipse.jgit.revwalk.RevCommit)1302 Test (org.junit.Test)650 RevWalk (org.eclipse.jgit.revwalk.RevWalk)333 ObjectId (org.eclipse.jgit.lib.ObjectId)295 Repository (org.eclipse.jgit.lib.Repository)273 IOException (java.io.IOException)222 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)190 Ref (org.eclipse.jgit.lib.Ref)174 File (java.io.File)134 ArrayList (java.util.ArrayList)134 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)133 Git (org.eclipse.jgit.api.Git)133 PersonIdent (org.eclipse.jgit.lib.PersonIdent)105 Change (com.google.gerrit.entities.Change)87 TestRepository (org.eclipse.jgit.junit.TestRepository)72 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)70 ObjectReader (org.eclipse.jgit.lib.ObjectReader)64 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)61 List (java.util.List)61 HashMap (java.util.HashMap)57