Example usage for org.eclipse.jgit.revwalk RevCommitList RevCommitList

List of usage examples for org.eclipse.jgit.revwalk RevCommitList RevCommitList

Introduction

In this page you can find the example usage for org.eclipse.jgit.revwalk RevCommitList RevCommitList.

Prototype

RevCommitList

Source Link

Usage

From source file:com.google.gerrit.server.git.MergeSorter.java

License:Apache License

Collection<CodeReviewCommit> sort(final Collection<CodeReviewCommit> incoming) throws IOException {
    final Set<CodeReviewCommit> heads = new HashSet<>();
    final Set<CodeReviewCommit> sort = new HashSet<>(incoming);
    while (!sort.isEmpty()) {
        final CodeReviewCommit n = removeOne(sort);

        rw.resetRetain(canMergeFlag);//from   w  w  w.  j ava  2  s . co  m
        rw.markStart(n);
        for (RevCommit c : accepted) {
            rw.markUninteresting(c);
        }

        CodeReviewCommit c;
        RevCommitList<RevCommit> contents = new RevCommitList<>();
        while ((c = rw.next()) != null) {
            if (!c.has(canMergeFlag) || !incoming.contains(c)) {
                // We cannot merge n as it would bring something we
                // aren't permitted to merge at this time. Drop n.
                //
                if (n.missing == null) {
                    n.setStatusCode(CommitMergeStatus.MISSING_DEPENDENCY);
                    n.missing = new ArrayList<>();
                }
                n.missing.add(c);
            } else {
                contents.add(c);
            }
        }

        if (n.getStatusCode() == CommitMergeStatus.MISSING_DEPENDENCY) {
            continue;
        }

        // Anything reachable through us is better merged by just
        // merging us directly. So prune our ancestors out and let
        // us merge instead.
        //
        sort.removeAll(contents);
        heads.removeAll(contents);
        heads.add(n);
    }
    return heads;
}

From source file:org.eclipse.egit.core.synchronize.GitSyncInfoTest.java

License:Open Source License

/**
 * Outgoing change should be returned when base RevCommitList has more
 * commits than remote RevCommitList/*from  w w  w. jav  a 2 s  .co m*/
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnOutgoingFileChange() throws Exception {
    // when

    // given
    String fileName = "test-file";
    byte[] localBytes = new byte[8200];
    Arrays.fill(localBytes, (byte) 'a');

    IFile local = createMock(IFile.class);
    expect(local.isDerived()).andReturn(false);
    expect(local.exists()).andReturn(true).times(2);
    expect(local.getName()).andReturn(fileName).anyTimes();
    expect(local.getProject()).andReturn(project.getProject());
    expect(local.getContents()).andReturn(new ByteArrayInputStream(localBytes));
    replay(local);

    stage(fileName, localBytes);
    RevCommit firstCommit = commit();
    localBytes[8120] = 'b';
    ObjectId objectId = stage(fileName, localBytes);
    RevCommit secondCommit = commit();
    RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
    baseCommits.add(firstCommit);
    baseCommits.add(secondCommit);

    IFile baseResource = createMock(IFile.class);
    replay(baseResource);
    GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource, repo, objectId, baseCommits); // baseComits has two entry

    IResource remoteResource = createMock(IResource.class);
    replay(remoteResource);
    RevCommitList<RevCommit> remoteCommits = new RevCommitList<RevCommit>();
    remoteCommits.add(firstCommit);
    GitBlobResourceVariant remote = new GitBlobResourceVariant(remoteResource, repo,
            ObjectId.fromString("0123456789012345678901234567890123456789"), remoteCommits); // remoteCommits has only one entry

    GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
    gsi.init();

    // then
    assertEquals(OUTGOING | CHANGE, gsi.getKind());
    verify(local, baseResource, remoteResource);
}

From source file:org.eclipse.egit.core.synchronize.GitSyncInfoTest.java

License:Open Source License

/**
 * Should return incoming change when remote RevCommitList has more commit
 * objects then base RevCommitList/*from ww w  .  ja v  a 2s. c  o  m*/
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnIncomingFileChange() throws Exception {
    // when

    // given
    String fileName = "test-file";
    byte[] localBytes = new byte[8200];
    Arrays.fill(localBytes, (byte) 'a');

    IFile local = createMock(IFile.class);
    expect(local.isDerived()).andReturn(false);
    expect(local.exists()).andReturn(true).times(2);
    expect(local.getName()).andReturn(fileName).anyTimes();
    expect(local.getProject()).andReturn(project.getProject());
    expect(local.getContents()).andReturn(new ByteArrayInputStream(localBytes));
    replay(local);

    ObjectId objectId = stage(fileName, localBytes);
    RevCommit firstCommit = commit();
    RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
    baseCommits.add(firstCommit);

    IFile baseResource = createMock(IFile.class);
    replay(baseResource);
    GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource, repo, objectId, baseCommits); // baseCommits has one element

    IResource remoteResource = createMock(IResource.class);
    replay(remoteResource);

    stage(fileName, localBytes);
    RevCommit secondCommit = commit();
    RevCommitList<RevCommit> remoteCommits = new RevCommitList<RevCommit>();
    remoteCommits.add(secondCommit);
    remoteCommits.add(firstCommit);
    GitBlobResourceVariant remote = new GitBlobResourceVariant(remoteResource, repo,
            ObjectId.fromString("0123456789012345678901234567890123456789"), remoteCommits); // remoteCommits has two elements

    GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
    gsi.init();

    // then
    assertEquals(INCOMING | CHANGE, gsi.getKind());
    verify(local, baseResource, remoteResource);
}

From source file:org.eclipse.egit.core.synchronize.GitSyncInfoTest.java

License:Open Source License

/**
 * Incoming deletion should be returned when file exists locally and in base
 * but does not exist in remote resource variant.
 * @throws Exception// w  w  w  .ja v a  2  s. co  m
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnIncomingFileDeletion() throws Exception {
    // when

    // given
    String fileName = "test-file";
    byte[] localBytes = new byte[8200];
    Arrays.fill(localBytes, (byte) 'a');

    IFile local = createMock(IFile.class);
    expect(local.isDerived()).andReturn(false);
    expect(local.exists()).andReturn(true).times(2);
    expect(local.getName()).andReturn(fileName).anyTimes();
    expect(local.getProject()).andReturn(project.getProject());
    expect(local.getContents()).andReturn(new ByteArrayInputStream(localBytes));
    replay(local);

    stage(fileName, localBytes);
    RevCommit firstCommit = commit();
    ObjectId objectId = stage(fileName, localBytes);
    RevCommit secondCommit = commit();
    RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
    baseCommits.add(firstCommit);
    baseCommits.add(secondCommit);

    IFile baseResource = createMock(IFile.class);
    replay(baseResource);
    GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource, repo, objectId, baseCommits);

    GitSyncInfo gsi = new GitSyncInfo(local, base, null, comparator);
    gsi.init();

    // then
    assertEquals(INCOMING | DELETION, gsi.getKind());
    verify(local, baseResource);
}

From source file:org.eclipse.egit.core.synchronize.GitSyncInfoTest.java

License:Open Source License

/**
 * Conflicting change should be returned when remote and base RevCommitList
 * have same number of RevCommit object's but these lists have one ore more
 * different RevCommit objects.//  w w w  .  j a  v  a2s .co m
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnConflictingFileChange() throws Exception {
    // when

    // given
    String fileName = "test-file";
    byte[] localBytes = new byte[8200];
    Arrays.fill(localBytes, (byte) 'a');

    IFile local = createMock(IFile.class);
    expect(local.isDerived()).andReturn(false);
    expect(local.exists()).andReturn(true).times(2);
    expect(local.getName()).andReturn(fileName).anyTimes();
    expect(local.getProject()).andReturn(project.getProject());
    expect(local.getContents()).andReturn(new ByteArrayInputStream(localBytes));
    replay(local);

    ObjectId objectId = stage(fileName, localBytes);
    RevCommit firstCommit = commit();
    RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
    baseCommits.add(firstCommit);

    IFile baseResource = createMock(IFile.class);
    replay(baseResource);
    GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource, repo, objectId, baseCommits);

    IResource remoteResource = createMock(IResource.class);
    replay(remoteResource);

    stage(fileName, localBytes);
    RevCommit secondCommit = commit();
    RevCommitList<RevCommit> remoteCommits = new RevCommitList<RevCommit>();
    remoteCommits.add(secondCommit);
    GitBlobResourceVariant remote = new GitBlobResourceVariant(remoteResource, repo,
            ObjectId.fromString("0123456789012345678901234567890123456789"), remoteCommits);

    GitSyncInfo gsi = new GitSyncInfo(local, base, remote, comparator);
    gsi.init();

    // then
    assertEquals(CONFLICTING | CHANGE, gsi.getKind());
    verify(local, baseResource, remoteResource);
}

From source file:org.eclipse.egit.core.synchronize.GitSyncInfoTest.java

License:Open Source License

/**
 * Conflicting change should be returned when local resource differ from
 * base resource variant and remote variant does not exist.
 * @throws Exception// w w  w .  j a v  a2s  .  com
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnConflictingFileChange2() throws Exception {
    // when

    // given
    String fileName = "test-file";
    byte[] localBytes = new byte[8200];
    Arrays.fill(localBytes, (byte) 'a');

    IFile local = createMock(IFile.class);
    expect(local.isDerived()).andReturn(false);
    expect(local.exists()).andReturn(true).times(2);
    expect(local.getName()).andReturn(fileName).anyTimes();
    expect(local.getProject()).andReturn(project.getProject());
    expect(local.getContents()).andReturn(new ByteArrayInputStream(localBytes));
    replay(local);

    stage(fileName, localBytes);
    RevCommit firstCommit = commit();
    byte[] remoteBytes = new byte[localBytes.length];
    System.arraycopy(localBytes, 0, remoteBytes, 0, localBytes.length);
    remoteBytes[8100] = 'b';
    ObjectId objectId = stage(fileName, remoteBytes);
    RevCommit secondCommit = commit();
    RevCommitList<RevCommit> baseCommits = new RevCommitList<RevCommit>();
    baseCommits.add(firstCommit);
    baseCommits.add(secondCommit);

    IFile baseResource = createMock(IFile.class);
    replay(baseResource);
    GitBlobResourceVariant base = new GitBlobResourceVariant(baseResource, repo, objectId, baseCommits);

    GitSyncInfo gsi = new GitSyncInfo(local, base, null, comparator);
    gsi.init();

    // then
    assertEquals(CONFLICTING | CHANGE, gsi.getKind());
    verify(local, baseResource);
}