Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.RevCommit


    protected abstract ObjectSerializingFactory getObjectSerializingFactory();

    @Test
    public void testCommitSerialization() throws IOException {
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here


    }

    @Test
    public void testCommitSerializationMultipleLinesMessage() throws IOException {
        testCommit.setMessage("this\n is a \n  multiple lines\n message");
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here

    @Test
    public void testCommitSerializationNoAuthor() throws IOException {
        testCommit.setAuthor(null);
        testCommit.setAuthorEmail(null);
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here

    @Test
    public void testCommitSerializationNoCommitter() throws IOException {
        testCommit.setCommitter(null);
        testCommit.setCommitterEmail(null);
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here

    }

    @Test
    public void testCommitSerializationNoMessage() throws IOException {
        testCommit.setMessage(null);
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here

    }

    @Test
    public void testCommitSerializationNoParents() throws IOException {
        testCommit.setParentIds(null);
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here

    @Test
    public void testCommitSerializationMultipleParents() throws IOException {
        testCommit.setParentIds(ImmutableList.of(ObjectId.forString("parent1"),
                ObjectId.forString("parent2"), ObjectId.forString("parent3"),
                ObjectId.forString("parent4")));
        RevCommit commit = testCommit.build();
        testCommit(commit);
    }
View Full Code Here

        writer.write(commit, out);

        // System.err.println(out);

        ObjectReader<RevCommit> reader = factory.createCommitReader();
        RevCommit read = reader.read(commit.getId(), new ByteArrayInputStream(out.toByteArray()));
        assertEquals(commit, read);
    }
View Full Code Here

        ObjectId parent1 = ObjectId.forString("Parent 1 of fake commit");
        ObjectId parent2 = ObjectId.forString("Parent 2 of fake commit");
        List<ObjectId> parents = Arrays.asList(parent1, parent2);
        builder.setParentIds(parents);

        RevCommit cmtIn = builder.build();
        assertNotNull(cmtIn);

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectWriter<RevCommit> write = factory.createObjectWriter(TYPE.COMMIT);
        write.write(cmtIn, bout);

        // System.err.println(bout);
        byte[] bytes = bout.toByteArray();
        assertTrue(bytes.length > 0);

        ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
        ObjectReader<RevCommit> read = factory.createCommitReader();

        RevCommit cmtOut = read.read(cmtIn.getId(), bin);

        assertEquals(treeId, cmtOut.getTreeId());
        assertEquals(parents, cmtOut.getParentIds());
        assertEquals(author, cmtOut.getAuthor().getName().get());
        assertEquals(authorEmail, cmtOut.getAuthor().getEmail().get());
        assertEquals(committer, cmtOut.getCommitter().getName().get());
        assertEquals(committerEmail, cmtOut.getCommitter().getEmail().get());
        assertEquals(currentTime, cmtOut.getCommitter().getTimestamp());
        assertEquals(timeZoneOffset, cmtOut.getCommitter().getTimeZoneOffset());
        assertEquals(currentTime, cmtOut.getAuthor().getTimestamp());
        assertEquals(timeZoneOffset, cmtOut.getAuthor().getTimeZoneOffset());

    }
View Full Code Here

     */
    private void fetchSparseCommit(ObjectId commitId, boolean allowEmpty) {

        Optional<RevObject> object = getObject(commitId);
        if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
            RevCommit commit = (RevCommit) object.get();

            FilteredDiffIterator changes = getFilteredChanges(commit);

            GraphDatabase graphDatabase = localRepository.graphDatabase();
            ObjectDatabase objectDatabase = localRepository.objectDatabase();
            graphDatabase.put(commit.getId(), commit.getParentIds());

            RevTree rootTree = RevTree.EMPTY;

            if (commit.getParentIds().size() > 0) {
                // Map this commit to the last "sparse" commit in my ancestry
                ObjectId mappedCommit = graphDatabase.getMapping(commit.getParentIds().get(0));
                graphDatabase.map(commit.getId(), mappedCommit);
                Optional<ObjectId> treeId = localRepository.command(ResolveTreeish.class)
                        .setTreeish(mappedCommit).call();
                if (treeId.isPresent()) {
                    rootTree = localRepository.getTree(treeId.get());
                }

            } else {
                graphDatabase.map(commit.getId(), ObjectId.NULL);
            }

            Iterator<DiffEntry> it = Iterators.filter(changes, new Predicate<DiffEntry>() {
                @Override
                public boolean apply(DiffEntry e) {
                    return true;
                }
            });

            if (it.hasNext()) {
                // Create new commit
                WriteTree writeTree = localRepository.command(WriteTree.class)
                        .setOldRoot(Suppliers.ofInstance(rootTree))
                        .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) it));

                if (changes.isAutoIngesting()) {
                    // the iterator already ingests objects into the ObjectDatabase
                    writeTree.dontMoveObjects();
                }

                ObjectId newTreeId = writeTree.call();

                CommitBuilder builder = new CommitBuilder(commit);
                List<ObjectId> newParents = new LinkedList<ObjectId>();
                for (ObjectId parentCommitId : commit.getParentIds()) {
                    newParents.add(graphDatabase.getMapping(parentCommitId));
                }
                builder.setParentIds(newParents);
                builder.setTreeId(newTreeId);

                RevCommit mapped = builder.build();
                objectDatabase.put(mapped);

                if (changes.wasFiltered()) {
                    graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");
                }

                graphDatabase.map(mapped.getId(), commit.getId());
                // Replace the old mapping with the new commit Id.
                graphDatabase.map(commit.getId(), mapped.getId());
            } else if (allowEmpty) {
                CommitBuilder builder = new CommitBuilder(commit);
                List<ObjectId> newParents = new LinkedList<ObjectId>();
                for (ObjectId parentCommitId : commit.getParentIds()) {
                    newParents.add(graphDatabase.getMapping(parentCommitId));
                }
                builder.setParentIds(newParents);
                builder.setTreeId(rootTree.getId());
                builder.setMessage(PLACEHOLDER_COMMIT_MESSAGE);

                RevCommit mapped = builder.build();
                objectDatabase.put(mapped);

                graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");

                graphDatabase.map(mapped.getId(), commit.getId());
                // Replace the old mapping with the new commit Id.
                graphDatabase.map(commit.getId(), mapped.getId());
            } else {
                // Mark the mapped commit as sparse, since it wont have these changes
                graphDatabase.setProperty(graphDatabase.getMapping(commit.getId()),
                        GraphDatabase.SPARSE_FLAG, "true");
            }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.RevCommit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.