Search in sources :

Example 1 with MutableTree

use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.

the class WriteTree2 method handleDeletedTrees.

private void handleDeletedTrees(TreeDifference treeDifference, Set<String> ignoreList) {
    SortedSet<NodeRef> deletes = treeDifference.findDeletes();
    for (NodeRef ref : deletes) {
        String path = ref.path();
        if (ignoreList.contains(path)) {
            continue;
        }
        ignoreList.add(path);
        if (!filterMatchesOrIsParent(path)) {
            if (filterApplies(path, treeDifference.getRightTree())) {
                // can't optimize
                RevTree newTree = applyChanges(ref, null);
                Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
                MutableTree leftTree = treeDifference.getLeftTree();
                leftTree.forceChild(ref.getParentPath(), newNode);
            }
        } else {
            MutableTree leftTree = treeDifference.getLeftTree();
            leftTree.removeChild(path);
        }
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 2 with MutableTree

use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.

the class WriteTree2 method handleNewTrees.

private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) {
    SortedSet<NodeRef> newTrees = treeDifference.findNewTrees();
    for (NodeRef ref : newTrees) {
        final String path = ref.path();
        if (ignoreList.contains(path)) {
            continue;
        }
        ignoreList.add(path);
        if (!filterMatchesOrIsParent(path)) {
            MutableTree rightTree = treeDifference.getRightTree();
            if (filterApplies(path, rightTree)) {
                // can't optimize
                RevTree newTree = applyChanges(null, ref);
                Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
                MutableTree leftTree = treeDifference.getLeftTree();
                leftTree.forceChild(ref.getParentPath(), newNode);
            }
        } else {
            LOGGER.trace("Creating new tree {}", path);
            deepMove(ref.getNode());
            MutableTree leftTree = treeDifference.getLeftTree();
            String parentPath = ref.getParentPath();
            Node node = ref.getNode();
            leftTree.setChild(parentPath, node);
        }
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 3 with MutableTree

use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.

the class WriteTree2 method handlePureMetadataChanges.

private void handlePureMetadataChanges(TreeDifference treeDifference, Set<String> ignoreList) {
    Map<NodeRef, NodeRef> pureMetadataChanges = treeDifference.findPureMetadataChanges();
    for (Map.Entry<NodeRef, NodeRef> e : pureMetadataChanges.entrySet()) {
        NodeRef newValue = e.getValue();
        String treePath = newValue.path();
        if (ignoreList.contains(treePath)) {
            continue;
        }
        ignoreList.add(treePath);
        if (!filterMatchesOrIsParent(treePath)) {
            // filter doesn't apply to the changed tree
            continue;
        }
        deepMove(newValue.getMetadataId());
        MutableTree leftTree = treeDifference.getLeftTree();
        leftTree.setChild(newValue.getParentPath(), newValue.getNode());
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 4 with MutableTree

use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.

the class WriteTree2 method handleRemainingDifferences.

private void handleRemainingDifferences(TreeDifference treeDifference, Set<String> ignoreList) {
    // old/new refs to trees that have changed and apply to the pathFilters, deepest paths first
    final SortedMap<NodeRef, NodeRef> changedTrees = treeDifference.findChanges();
    // filterChanges(changedTrees);
    final SortedMap<NodeRef, NodeRef> filteredChangedTrees = changedTrees;
    for (Map.Entry<NodeRef, NodeRef> changedTreeRefs : filteredChangedTrees.entrySet()) {
        NodeRef leftTreeRef = changedTreeRefs.getKey();
        NodeRef rightTreeRef = changedTreeRefs.getValue();
        String newPath = rightTreeRef.path();
        if (ignoreList.contains(newPath)) {
            continue;
        }
        if (!filterApplies(newPath, treeDifference.getRightTree())) {
            continue;
        }
        ignoreList.add(newPath);
        RevTree tree = applyChanges(leftTreeRef, rightTreeRef);
        Envelope bounds = SpatialOps.boundsOf(tree);
        Node newTreeNode = Node.create(rightTreeRef.name(), tree.getId(), rightTreeRef.getMetadataId(), TYPE.TREE, bounds);
        MutableTree leftRoot = treeDifference.getLeftTree();
        String parentPath = rightTreeRef.getParentPath();
        leftRoot.setChild(parentPath, newTreeNode);
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map) SortedMap(java.util.SortedMap) RevTree(org.locationtech.geogig.api.RevTree)

Example 5 with MutableTree

use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.

the class WriteTree2 method _call.

/**
     * Executes the write tree operation.
     * 
     * @return the new root tree id, the current HEAD tree id if there are no differences between
     *         the index and the HEAD, or {@code null} if the operation has been cancelled (as
     *         indicated by the {@link #getProgressListener() progress listener}.
     */
@Override
protected ObjectId _call() {
    final ProgressListener progress = getProgressListener();
    TreeDifference treeDifference = computeTreeDifference();
    if (treeDifference.areEqual()) {
        MutableTree leftTree = treeDifference.getLeftTree();
        Node leftNode = leftTree.getNode();
        ObjectId leftOid = leftNode.getObjectId();
        return leftOid;
    }
    final MutableTree oldLeftTree = treeDifference.getLeftTree().clone();
    Preconditions.checkState(oldLeftTree.equals(treeDifference.getLeftTree()));
    // handle renames before new and deleted trees for the computation of new and deleted to be
    // accurate
    Set<String> ignoreList = Sets.newHashSet();
    handleRenames(treeDifference, ignoreList);
    handlePureMetadataChanges(treeDifference, ignoreList);
    handleNewTrees(treeDifference, ignoreList);
    handleDeletedTrees(treeDifference, ignoreList);
    handleRemainingDifferences(treeDifference, ignoreList);
    progress.complete();
    MutableTree newLeftTree = treeDifference.getLeftTree();
    final ObjectDatabase repositoryDatabase = objectDatabase();
    final RevTree newRoot = newLeftTree.build(stagingDatabase(), repositoryDatabase);
    if (newRoot.trees().isPresent()) {
        for (Node n : newRoot.trees().get()) {
            if (n.getMetadataId().isPresent())
                deepMove(n.getMetadataId().get());
        }
    }
    ObjectId newRootId = newRoot.getId();
    return newRootId;
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) ProgressListener(org.locationtech.geogig.api.ProgressListener) ObjectId(org.locationtech.geogig.api.ObjectId) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) Node(org.locationtech.geogig.api.Node) TreeDifference(org.locationtech.geogig.api.plumbing.diff.TreeDifference) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

MutableTree (org.locationtech.geogig.api.plumbing.diff.MutableTree)8 NodeRef (org.locationtech.geogig.api.NodeRef)6 RevTree (org.locationtech.geogig.api.RevTree)5 Node (org.locationtech.geogig.api.Node)4 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 ObjectId (org.locationtech.geogig.api.ObjectId)2 TreeDifference (org.locationtech.geogig.api.plumbing.diff.TreeDifference)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Iterator (java.util.Iterator)1 ProgressListener (org.locationtech.geogig.api.ProgressListener)1 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)1