Search in sources :

Example 1 with RevTree

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

the class WorkingTreeInsertHelper method findOrCreateTree.

private NodeRef findOrCreateTree(final String treePath, final FeatureType type) {
    RevTree tree = context.command(FindOrCreateSubtree.class).setChildPath(treePath).setIndex(true).setParent(workHead).setParentPath(NodeRef.ROOT).call();
    ObjectId metadataId = ObjectId.NULL;
    if (type != null) {
        RevFeatureType revFeatureType = RevFeatureTypeImpl.build(type);
        if (tree.isEmpty()) {
            indexDatabase.put(revFeatureType);
        }
        metadataId = revFeatureType.getId();
    }
    Envelope bounds = SpatialOps.boundsOf(tree);
    Node node = Node.create(NodeRef.nodeFromPath(treePath), tree.getId(), metadataId, TYPE.TREE, bounds);
    String parentPath = NodeRef.parentPath(treePath);
    return new NodeRef(node, parentPath, ObjectId.NULL);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) FindOrCreateSubtree(org.locationtech.geogig.api.plumbing.FindOrCreateSubtree) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 2 with RevTree

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

the class WorkingTree method createTypeTree.

public synchronized NodeRef createTypeTree(final String treePath, final FeatureType featureType) {
    final RevTree workHead = getTree();
    Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(workHead).setChildPath(treePath).call();
    final RevFeatureType revType = RevFeatureTypeImpl.build(featureType);
    if (typeTreeRef.isPresent()) {
        throw new IllegalArgumentException("Tree already exists at " + treePath);
    }
    indexDatabase.put(revType);
    final ObjectId metadataId = revType.getId();
    final RevTree newTree = new RevTreeBuilder(indexDatabase).build();
    ObjectId newWorkHeadId = context.command(WriteBack.class).setToIndex(true).setAncestor(workHead.builder(indexDatabase)).setChildPath(treePath).setTree(newTree).setMetadataId(metadataId).call();
    updateWorkHead(newWorkHeadId);
    return context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(treePath).call().get();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 3 with RevTree

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

the class RevTreeBuilder2 method build.

/**
     * Traverses the nodes in the {@link NodeIndex}, deletes the ones with {@link ObjectId#NULL
     * NULL} ObjectIds, and adds the ones with non "NULL" ids.
     * 
     * @return the new tree, not saved to the object database. Any bucket tree though is saved when
     *         this method returns.
     */
public RevTree build() {
    if (nodeIndex == null) {
        return original.builder(db).build();
    }
    Stopwatch sw = Stopwatch.createStarted();
    RevTreeBuilder builder;
    try {
        builder = new RevTreeBuilder(db, original);
        Iterator<Node> nodes = nodeIndex.nodes();
        while (nodes.hasNext()) {
            Node node = nodes.next();
            if (node.getObjectId().isNull()) {
                builder.remove(node.getName());
            } else {
                builder.put(node);
            }
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    } finally {
        nodeIndex.close();
    }
    LOGGER.debug("Index traversed in {}", sw.stop());
    sw.reset().start();
    RevTree namedTree = builder.build();
    saveExtraFeatureTypes();
    LOGGER.debug("RevTreeBuilder.build() in {}", sw.stop());
    return namedTree;
}
Also used : Node(org.locationtech.geogig.api.Node) Stopwatch(com.google.common.base.Stopwatch) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Example 4 with RevTree

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

the class MergeOpTest method testMergeMultiple.

@Test
public void testMergeMultiple() throws Exception {
    // Create the following revision graph
    // . o
    // . |
    // . o - Points 1 added
    // . |\
    // . | o - branch1 - Points 2 added
    // . |
    // . o - Points 3 added
    // ./|
    // o | - branch 2 - Lines 1 added
    // . |
    // . o - master - HEAD - Lines 2 added
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // create branch1 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    // checkout master, then create branch2 and checkout
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(lines2);
    final RevCommit c5 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
    // Merge branch1 and branch2 into master to create the following revision graph
    // . o
    // . |
    // . o - Points 1 added
    // . |\
    // . | o - branch1 - Points 2 added
    // . | |
    // . o | - Points 3 added
    // ./| |
    // o | | - branch 2 - Lines 1 added
    // | | |
    // | o | - Lines 2 added
    // .\|/
    // . o - master - HEAD - Merge commit
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
    final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).addCommit(Suppliers.ofInstance(branch2.getObjectId())).setMessage("My merge message.").call();
    RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
    String path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points2.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points3.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines2.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();
    // Commit 4
    RevCommit logC4 = log.next();
    assertEquals("My merge message.", logC4.getMessage());
    assertEquals(3, logC4.getParentIds().size());
    assertEquals(c5.getId(), logC4.getParentIds().get(0));
    assertEquals(c2.getId(), logC4.getParentIds().get(1));
    assertEquals(c4.getId(), logC4.getParentIds().get(2));
    // Commit 3
    RevCommit logC3 = log.next();
    assertEquals(c5.getAuthor(), logC3.getAuthor());
    assertEquals(c5.getCommitter(), logC3.getCommitter());
    assertEquals(c5.getMessage(), logC3.getMessage());
    assertEquals(c5.getTreeId(), logC3.getTreeId());
    // Commit 2
    RevCommit logC2 = log.next();
    assertEquals(c3.getAuthor(), logC2.getAuthor());
    assertEquals(c3.getCommitter(), logC2.getCommitter());
    assertEquals(c3.getMessage(), logC2.getMessage());
    assertEquals(c3.getTreeId(), logC2.getTreeId());
    // Commit 1
    RevCommit logC1 = log.next();
    assertEquals(c1.getAuthor(), logC1.getAuthor());
    assertEquals(c1.getCommitter(), logC1.getCommitter());
    assertEquals(c1.getMessage(), logC1.getMessage());
    assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 5 with RevTree

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

the class MergeOpTest method testMerge.

@Test
public void testMerge() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // |
    // o - Points 3 added
    // |
    // o - master - HEAD - Lines 1 added
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // create branch1 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    // checkout master
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    // Merge branch1 into master to create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // | |
    // o | - Points 3 added
    // | |
    // o | - Lines 1 added
    // |/
    // o - master - HEAD - Merge commit
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).setMessage("My merge message.").call();
    RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
    String path = appendChild(pointsName, points2.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points3.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // Merge Commit
    RevCommit logCmerge = log.next();
    assertEquals("My merge message.", logCmerge.getMessage());
    assertEquals(2, logCmerge.getParentIds().size());
    assertEquals(c4.getId(), logCmerge.getParentIds().get(0));
    assertEquals(c2.getId(), logCmerge.getParentIds().get(1));
    // Commit 4
    RevCommit logC4 = log.next();
    assertEquals(c4.getAuthor(), logC4.getAuthor());
    assertEquals(c4.getCommitter(), logC4.getCommitter());
    assertEquals(c4.getMessage(), logC4.getMessage());
    assertEquals(c4.getTreeId(), logC4.getTreeId());
    // Commit 3
    RevCommit logC3 = log.next();
    assertEquals(c3.getAuthor(), logC3.getAuthor());
    assertEquals(c3.getCommitter(), logC3.getCommitter());
    assertEquals(c3.getMessage(), logC3.getMessage());
    assertEquals(c3.getTreeId(), logC3.getTreeId());
    // Commit 2
    RevCommit logC2 = log.next();
    assertEquals(c2.getAuthor(), logC2.getAuthor());
    assertEquals(c2.getCommitter(), logC2.getCommitter());
    assertEquals(c2.getMessage(), logC2.getMessage());
    assertEquals(c2.getTreeId(), logC2.getTreeId());
    // Commit 1
    RevCommit logC1 = log.next();
    assertEquals(c1.getAuthor(), logC1.getAuthor());
    assertEquals(c1.getCommitter(), logC1.getCommitter());
    assertEquals(c1.getMessage(), logC1.getMessage());
    assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

RevTree (org.locationtech.geogig.api.RevTree)214 Test (org.junit.Test)120 ObjectId (org.locationtech.geogig.api.ObjectId)91 NodeRef (org.locationtech.geogig.api.NodeRef)73 Node (org.locationtech.geogig.api.Node)56 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)47 RevCommit (org.locationtech.geogig.api.RevCommit)36 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)29 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)27 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)24 RevObject (org.locationtech.geogig.api.RevObject)21 RevFeature (org.locationtech.geogig.api.RevFeature)18 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)18 Bucket (org.locationtech.geogig.api.Bucket)17 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)17 File (java.io.File)16 Ref (org.locationtech.geogig.api.Ref)16 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)15 GeoGIG (org.locationtech.geogig.api.GeoGIG)14 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)14