Search in sources :

Example 61 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class LocalMappedRemoteRepo method pushSparseCommit.

/**
     * This function takes all of the changes introduced by a commit on the sparse repository and
     * creates a new commit on the full repository with those changes.
     * 
     * @param commitId the commit id of commit from the sparse repository
     * @param from the sparse repository
     * @param to the full repository
     */
protected void pushSparseCommit(ObjectId commitId) {
    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());
    }
}
Also used : CheckSparsePath(org.locationtech.geogig.api.plumbing.CheckSparsePath) WriteTree(org.locationtech.geogig.api.plumbing.WriteTree) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) LinkedList(java.util.LinkedList) Repository(org.locationtech.geogig.repository.Repository) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 62 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class BinaryPackedObjects method ingest.

/**
     * @return the number of objects parsed from the input stream
     */
public IngestResults ingest(final InputStream in, final Callback callback) {
    Iterator<RevObject> objects = streamToObjects(in);
    BulkOpListener listener = new BulkOpListener() {

        @Override
        public void inserted(final ObjectId objectId, @Nullable Integer storageSizeBytes) {
            callback.callback(new Supplier<RevObject>() {

                @Override
                public RevObject get() {
                    return database.get(objectId);
                }
            });
        }
    };
    CountingListener countingListener = BulkOpListener.newCountingListener();
    listener = BulkOpListener.composite(countingListener, listener);
    database.putAll(objects, listener);
    return new IngestResults(countingListener.inserted(), countingListener.found());
}
Also used : CountingListener(org.locationtech.geogig.storage.BulkOpListener.CountingListener) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) BulkOpListener(org.locationtech.geogig.storage.BulkOpListener) Nullable(javax.annotation.Nullable)

Example 63 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class BinaryPackedObjects method write.

/**
     * @return the number of objects written
     */
public long write(ObjectFunnel funnel, List<ObjectId> want, List<ObjectId> have, Set<ObjectId> sent, Callback callback, boolean traverseCommits, Deduplicator deduplicator) throws IOException {
    for (ObjectId i : want) {
        if (!database.exists(i)) {
            throw new NoSuchElementException(format("Wanted commit: '%s' is not known", i));
        }
    }
    LOGGER.info("scanning for previsit list...");
    Stopwatch sw = Stopwatch.createStarted();
    ImmutableList<ObjectId> needsPrevisit = traverseCommits ? scanForPrevisitList(want, have, deduplicator) : ImmutableList.copyOf(have);
    LOGGER.info(String.format("Previsit list built in %s for %,d ids: %s. Calculating reachable content ids...", sw.stop(), needsPrevisit.size(), needsPrevisit));
    deduplicator.reset();
    sw.reset().start();
    ImmutableList<ObjectId> previsitResults = reachableContentIds(needsPrevisit, deduplicator);
    LOGGER.info(String.format("reachableContentIds took %s for %,d ids", sw.stop(), previsitResults.size()));
    deduplicator.reset();
    LOGGER.info("obtaining post order iterator on range...");
    sw.reset().start();
    Iterator<RevObject> objects = PostOrderIterator.range(want, new ArrayList<ObjectId>(previsitResults), database, traverseCommits, deduplicator);
    long objectCount = 0;
    LOGGER.info("PostOrderIterator.range took {}", sw.stop());
    try {
        LOGGER.info("writing objects to remote...");
        while (objects.hasNext()) {
            RevObject object = objects.next();
            funnel.funnel(object);
            objectCount++;
            callback.callback(Suppliers.ofInstance(object));
        }
    } catch (IOException e) {
        String causeMessage = Throwables.getRootCause(e).getMessage();
        LOGGER.info(String.format("writing of objects failed after %,d objects. Cause: '%s'", objectCount, causeMessage));
        throw e;
    }
    return objectCount;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 64 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class FilteredDiffIterator method computeNext.

/**
     * Compute the next {@link DiffEntry} that matches our {@link RepositoryFilter}.
     */
protected DiffEntry computeNext() {
    while (source.hasNext()) {
        DiffEntry input = source.next();
        // DiffTree) that doesn't report tree changes even is setReportTrees(true) was set.
        if (input.isChange() && input.getOldObject().getType().equals(TYPE.TREE)) {
            continue;
        }
        NodeRef oldObject = filter(input.getOldObject());
        NodeRef newObject;
        if (oldObject != null) {
            newObject = input.getNewObject();
            if (newObject != null) {
                // we are tracking this object, but we still need to process the new object
                RevObject object = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getNode().getObjectId()).call().get();
                RevObject metadata = null;
                if (newObject.getMetadataId() != ObjectId.NULL) {
                    metadata = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call().get();
                }
                processObject(object);
                processObject(metadata);
            }
        } else {
            newObject = filter(input.getNewObject());
        }
        if (oldObject == null && newObject == null) {
            filtered = true;
            continue;
        }
        return new DiffEntry(oldObject, newObject);
    }
    return endOfData();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevObject(org.locationtech.geogig.api.RevObject) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 65 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class FilteredDiffIterator method filter.

private NodeRef filter(NodeRef node) {
    if (node == null) {
        return null;
    }
    RevObject object = sourceRepo.objectDatabase().get(node.objectId());
    RevObject metadata = null;
    if (!node.getMetadataId().isNull()) {
        metadata = sourceRepo.objectDatabase().get(node.getMetadataId());
    }
    if (node.getType() == TYPE.FEATURE) {
        if (trackingObject(object.getId())) {
            // We are already tracking this object, continue to do so
            return node;
        }
        RevFeatureType revFeatureType = (RevFeatureType) metadata;
        if (!repoFilter.filterObject(revFeatureType, node.getParentPath(), object)) {
            return null;
        }
    }
    processObject(object);
    processObject(metadata);
    return node;
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8