Search in sources :

Example 6 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)

Example 7 with MutableTree

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

the class WriteTree2 method handleRenames.

/**
     * A renamed tree is recognized by checking if a tree on the right points to the same object
     * that a tree on the left that doesn't exist anymore on the right.
     * <p>
     * Left entries are the original ones, and right entries are the new ones.
     * </p>
     * 
     * @param treeDifference
     * @param ignoreList
     */
private void handleRenames(TreeDifference treeDifference, Set<String> ignoreList) {
    final SortedMap<NodeRef, NodeRef> renames = treeDifference.findRenames();
    for (Map.Entry<NodeRef, NodeRef> e : renames.entrySet()) {
        NodeRef oldValue = e.getKey();
        NodeRef newValue = e.getValue();
        String newPath = newValue.path();
        if (ignoreList.contains(newPath)) {
            continue;
        }
        ignoreList.add(newPath);
        if (!filterMatchesOrIsParent(newPath)) {
            // filter doesn't apply to the renamed tree as a whole
            continue;
        }
        LOGGER.trace("Handling rename of {} as {}", oldValue.path(), newPath);
        MutableTree leftTree = treeDifference.getLeftTree();
        leftTree.removeChild(oldValue.path());
        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 8 with MutableTree

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

the class WriteTree2 method computeTreeDifference.

private TreeDifference computeTreeDifference() {
    final String rightTreeish = Ref.STAGE_HEAD;
    final ObjectId rootTreeId = resolveRootTreeId();
    final ObjectId stageRootId = index().getTree().getId();
    final Supplier<Iterator<NodeRef>> leftTreeRefs;
    final Supplier<Iterator<NodeRef>> rightTreeRefs;
    if (rootTreeId.isNull()) {
        Iterator<NodeRef> empty = Iterators.emptyIterator();
        leftTreeRefs = Suppliers.ofInstance(empty);
    } else {
        leftTreeRefs = command(LsTreeOp.class).setReference(rootTreeId.toString()).setStrategy(Strategy.DEPTHFIRST_ONLY_TREES);
    }
    rightTreeRefs = command(LsTreeOp.class).setReference(rightTreeish).setStrategy(Strategy.DEPTHFIRST_ONLY_TREES);
    MutableTree leftTree = MutableTree.createFromRefs(rootTreeId, leftTreeRefs);
    MutableTree rightTree = MutableTree.createFromRefs(stageRootId, rightTreeRefs);
    TreeDifference treeDifference = TreeDifference.create(leftTree, rightTree);
    return treeDifference;
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Iterator(java.util.Iterator) TreeDifference(org.locationtech.geogig.api.plumbing.diff.TreeDifference)

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