Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.RevCommit


    }

    @Test
    public void testExportDiff() throws Exception {
        insertAndAdd(points1);
        final RevCommit insertCommit = geogig.command(CommitOp.class).setAll(true).call();

        final String featureId = points1.getIdentifier().getID();
        final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId,
                "changedProp", new Integer(1500));
        insertAndAdd(modifiedFeature, points2);
        final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();

        Feature[] points = new Feature[] { modifiedFeature, points2 };

        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("geogig_fid", String.class);
        for (AttributeDescriptor descriptor : pointsType.getAttributeDescriptors()) {
            builder.add(descriptor);
        }
        builder.setName(pointsType.getName());
        builder.setCRS(pointsType.getCoordinateReferenceSystem());
        SimpleFeatureType outputFeatureType = builder.buildFeatureType();
        MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName)
                .setNewRef(changeCommit.getId().toString())
                .setOldRef(insertCommit.getId().toString()).call();
        featureSource = dataStore.getFeatureSource(typeName);
        featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection featureCollection = featureStore.getFeatures();
        assertEquals(featureCollection.size(), points.length);
View Full Code Here


    }

    @Test
    public void testExportDiffUsingOldVersion() throws Exception {
        insertAndAdd(points1);
        final RevCommit insertCommit = geogig.command(CommitOp.class).setAll(true).call();

        final String featureId = points1.getIdentifier().getID();
        final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId,
                "changedProp", new Integer(1500));
        insertAndAdd(modifiedFeature, points2);
        final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();

        Feature[] points = new Feature[] { points1 };
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.add("geogig_fid", String.class);
        for (AttributeDescriptor descriptor : pointsType.getAttributeDescriptors()) {
            builder.add(descriptor);
        }
        builder.setName(pointsType.getName());
        builder.setCRS(pointsType.getCoordinateReferenceSystem());
        SimpleFeatureType outputFeatureType = builder.buildFeatureType();
        MemoryDataStore dataStore = new MemoryDataStore(outputFeatureType);
        final String typeName = dataStore.getTypeNames()[0];
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
        SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
        geogig.command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(pointsName)
                .setNewRef(changeCommit.getId().toString())
                .setOldRef(insertCommit.getId().toString()).setUseOld(true).call();
        featureSource = dataStore.getFeatureSource(typeName);
        featureStore = (SimpleFeatureStore) featureSource;
        SimpleFeatureCollection featureCollection = featureStore.getFeatures();
        assertEquals(featureCollection.size(), points.length);
View Full Code Here

        public boolean put(RevObject object) {

            final boolean inserted = super.put(object);

            if (inserted && RevObject.TYPE.COMMIT.equals(object.getType())) {
                RevCommit commit = (RevCommit) object;
                graphDb.get().put(commit.getId(), commit.getParentIds());
            }
            return inserted;
        }
View Full Code Here

                        private final GraphDatabase graphDatabase = graphDb.get();

                        @Override
                        public RevObject apply(RevObject input) {
                            if (input instanceof RevCommit) {
                                RevCommit commit = (RevCommit) input;
                                ObjectId commitId = commit.getId();
                                ImmutableList<ObjectId> parentIds = commit.getParentIds();
                                graphDatabase.put(commitId, parentIds);

                                // addedCommits.add((RevCommit) input);
                            }
                            return input;
View Full Code Here

    protected void pushSparseCommit(ObjectId commitId) {
        Repository from = localRepository;
        Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId)
                .call();
        if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
            RevCommit commit = (RevCommit) object.get();
            ObjectId parent = ObjectId.NULL;
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (int i = 0; i < commit.getParentIds().size(); i++) {
                ObjectId parentId = commit.getParentIds().get(i);
                if (i != 0) {
                    Optional<ObjectId> commonAncestor = from.command(FindCommonAncestor.class)
                            .setLeftId(commit.getParentIds().get(0)).setRightId(parentId).call();
                    if (commonAncestor.isPresent()) {
                        if (from.command(CheckSparsePath.class).setStart(parentId)
                                .setEnd(commonAncestor.get()).call()) {
                            // This should be the base commit to preserve changes that were filtered
                            // out.
                            newParents.add(0, from.graphDatabase().getMapping(parentId));
                            continue;
                        }
                    }
                }
                newParents.add(from.graphDatabase().getMapping(parentId));
            }
            if (newParents.size() > 0) {
                parent = from.graphDatabase().getMapping(newParents.get(0));
            }
            Iterator<DiffEntry> diffIter = from.command(DiffOp.class).setNewVersion(commitId)
                    .setOldVersion(parent).setReportTrees(true).call();

            // connect and send packed changes
            final URL resourceURL;
            try {
                resourceURL = new URL(repositoryURL.toString() + "/repo/applychanges");
            } catch (MalformedURLException e) {
                throw Throwables.propagate(e);
            }

            final HttpURLConnection connection;
            final OutputStream out;
            try {
                connection = (HttpURLConnection) resourceURL.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                out = connection.getOutputStream();
                // pack the commit object
                final ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
                final ObjectWriter<RevCommit> commitWriter = factory
                        .createObjectWriter(TYPE.COMMIT);
                commitWriter.write(commit, out);

                // write the new parents
                out.write(newParents.size());
                for (ObjectId parentId : newParents) {
                    out.write(parentId.getRawValue());
                }

                // pack the changes
                BinaryPackedChanges changes = new BinaryPackedChanges(from);
                changes.write(out, diffIter);
            } catch (IOException e) {
                throw Throwables.propagate(e);
            }

            final InputStream in;
            try {
                in = connection.getInputStream();
                BufferedReader rd = new BufferedReader(new InputStreamReader(in));

                String line = rd.readLine();
                if (line != null) {
                    ObjectId remoteCommitId = ObjectId.valueOf(line);
                    from.graphDatabase().map(commit.getId(), remoteCommitId);
                    from.graphDatabase().map(remoteCommitId, commit.getId());
                }

            } catch (IOException e) {
                throw Throwables.propagate(e);
            }
View Full Code Here

     * @throws XMLStreamException
     */
    public void writeCommits(Iterator<RevCommit> entries, int elementsPerPage, boolean returnRange)
            throws XMLStreamException {
        int counter = 0;
        RevCommit lastCommit = null;
        if (returnRange) {
            if (entries.hasNext()) {
                lastCommit = entries.next();
                writeCommit(lastCommit, "untilCommit", null, null, null);
                counter++;
View Full Code Here

                        if (input.getOurs().equals(ObjectId.NULL)) {
                            commitId = theirs;
                        }
                        Optional<RevObject> object = geogig.command(RevObjectParse.class)
                                .setObjectId(commitId).call();
                        RevCommit commit = null;
                        if (object.isPresent() && object.get() instanceof RevCommit) {
                            commit = (RevCommit) object.get();
                        } else {
                            throw new CommandSpecException("Couldn't resolve id: "
                                    + commitId.toString() + " to a commit");
                        }

                        object = geogig.command(RevObjectParse.class)
                                .setObjectId(commit.getTreeId()).call();
                        Optional<NodeRef> node = Optional.absent();
                        if (object.isPresent()) {
                            RevTree tree = (RevTree) object.get();
                            node = geogig.command(FindTreeChild.class).setParent(tree)
                                    .setChildPath(input.getPath()).call();
View Full Code Here

        Map<String, ValueAndCommit> changes = report.getChanges();
        Iterator<String> iter = changes.keySet().iterator();
        while (iter.hasNext()) {
            String attrib = iter.next();
            ValueAndCommit valueAndCommit = changes.get(attrib);
            RevCommit commit = valueAndCommit.commit;
            Optional<?> value = valueAndCommit.value;
            out.writeStartElement("Attribute");
            writeElement("name", attrib);
            writeElement("value",
                    TextValueSerializer.asString(Optional.fromNullable((Object) value.orNull())));
View Full Code Here

            final Ref remoteHead = headRef();
            if (remoteHead instanceof SymRef) {
                if (((SymRef) remoteHead).getTarget().equals(updatedRef.get().getName())) {
                    remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD)
                            .setNewValue(updatedRef.get().getName()).call();
                    RevCommit commit = remoteGeoGig.getRepository().getCommit(commitId);
                    remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
                    remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
                }
            }
        }
        return updatedRef;
    }
View Full Code Here

        Repository from = localRepository;
        Repository to = remoteGeoGig.getRepository();
        Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId)
                .call();
        if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
            RevCommit commit = (RevCommit) object.get();
            ObjectId parent = ObjectId.NULL;
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (int i = 0; i < commit.getParentIds().size(); i++) {
                ObjectId parentId = commit.getParentIds().get(i);
                if (i != 0) {
                    Optional<ObjectId> commonAncestor = from.command(FindCommonAncestor.class)
                            .setLeftId(commit.getParentIds().get(0)).setRightId(parentId).call();
                    if (commonAncestor.isPresent()) {
                        if (from.command(CheckSparsePath.class).setStart(parentId)
                                .setEnd(commonAncestor.get()).call()) {
                            // This should be the base commit to preserve the sparse changes that
                            // were filtered
                            // out.
                            newParents.add(0, from.graphDatabase().getMapping(parentId));
                            continue;
                        }
                    }
                }
                newParents.add(from.graphDatabase().getMapping(parentId));
            }
            if (newParents.size() > 0) {
                parent = from.graphDatabase().getMapping(newParents.get(0));
            }
            Iterator<DiffEntry> diffIter = from.command(DiffOp.class).setNewVersion(commitId)
                    .setOldVersion(parent).setReportTrees(true).call();

            LocalCopyingDiffIterator changes = new LocalCopyingDiffIterator(diffIter, from, to);

            RevTree rootTree = RevTree.EMPTY;

            if (newParents.size() > 0) {
                ObjectId mappedCommit = newParents.get(0);

                Optional<ObjectId> treeId = to.command(ResolveTreeish.class)
                        .setTreeish(mappedCommit).call();
                if (treeId.isPresent()) {
                    rootTree = to.getTree(treeId.get());
                }
            }

            // Create new commit
            ObjectId newTreeId = to.command(WriteTree.class)
                    .setOldRoot(Suppliers.ofInstance(rootTree))
                    .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) changes)).call();

            CommitBuilder builder = new CommitBuilder(commit);
            builder.setParentIds(newParents);
            builder.setTreeId(newTreeId);

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

            from.graphDatabase().map(commit.getId(), mapped.getId());
            from.graphDatabase().map(mapped.getId(), commit.getId());

        }
    }
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.