Search in sources :

Example 26 with RevObject

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

the class LsTreeOp method _call.

/**
     * @see java.util.concurrent.Callable#call()
     */
protected Iterator<NodeRef> _call() {
    String ref = this.ref;
    if (ref == null) {
        ref = Ref.WORK_HEAD;
    }
    ObjectId metadataId = ObjectId.NULL;
    final String path = ref.lastIndexOf(':') != -1 ? ref.substring(ref.lastIndexOf(':') + 1) : "";
    if (!path.isEmpty()) {
        final String providedRefName = ref.lastIndexOf(':') != -1 ? ref.substring(0, ref.lastIndexOf(':')) : null;
        if (providedRefName != null) {
            Optional<ObjectId> rootTreeId = command(ResolveTreeish.class).setTreeish(providedRefName).call();
            if (rootTreeId.isPresent()) {
                RevTree rootTree = command(RevObjectParse.class).setObjectId(rootTreeId.get()).call(RevTree.class).get();
                Optional<NodeRef> treeRef = command(FindTreeChild.class).setChildPath(path).setIndex(true).setParent(rootTree).call();
                metadataId = treeRef.isPresent() ? treeRef.get().getMetadataId() : ObjectId.NULL;
            }
        }
    }
    // is it just a ref name?
    Optional<Ref> reference = command(RefParse.class).setName(ref).call();
    if (reference.isPresent()) {
        if (reference.get().getObjectId().isNull()) {
            return Iterators.emptyIterator();
        }
    }
    Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
    Optional<NodeRef> treeRef = Optional.absent();
    if (!revObject.isPresent()) {
        if (Ref.WORK_HEAD.equals(ref)) {
            // tree but it is empty
            return Iterators.emptyIterator();
        }
        // let's try to see if it is a feature type or feature in the working tree
        NodeRef.checkValidPath(ref);
        treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
        Preconditions.checkArgument(treeRef.isPresent(), "Invalid reference: %s", ref);
        ObjectId treeId = treeRef.get().objectId();
        metadataId = treeRef.get().getMetadataId();
        revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
    }
    checkArgument(revObject.isPresent(), "Invalid reference: %s", ref);
    final TYPE type = revObject.get().getType();
    switch(type) {
        case FEATURE:
            NodeRef nodeRef = treeRef.isPresent() ? treeRef.get() : null;
            List<NodeRef> nodeRefs = Lists.newArrayList();
            nodeRefs.add(nodeRef);
            // If show trees options is passed in show all trees that contain this feature
            if (this.strategy == Strategy.TREES_ONLY) {
                if (nodeRef != null) {
                    while (!nodeRef.getParentPath().isEmpty()) {
                        treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(nodeRef.getParentPath()).setIndex(true).call();
                        nodeRef = treeRef.get();
                        nodeRefs.add(nodeRef);
                    }
                }
            }
            return nodeRefs.iterator();
        case COMMIT:
            RevCommit revCommit = (RevCommit) revObject.get();
            ObjectId treeId = revCommit.getTreeId();
            revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
        case TREE:
            DepthTreeIterator.Strategy iterStrategy;
            switch(this.strategy) {
                case CHILDREN:
                    iterStrategy = DepthTreeIterator.Strategy.CHILDREN;
                    break;
                case FEATURES_ONLY:
                    iterStrategy = DepthTreeIterator.Strategy.FEATURES_ONLY;
                    break;
                case TREES_ONLY:
                    iterStrategy = DepthTreeIterator.Strategy.TREES_ONLY;
                    break;
                case DEPTHFIRST:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE;
                    break;
                case DEPTHFIRST_ONLY_FEATURES:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_FEATURES_ONLY;
                    break;
                case DEPTHFIRST_ONLY_TREES:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_TREES_ONLY;
                    break;
                default:
                    throw new IllegalStateException("Unknown strategy: " + this.strategy);
            }
            RevTree tree = (RevTree) revObject.get();
            ObjectDatabase database = stagingDatabase();
            DepthTreeIterator iter = new DepthTreeIterator(path, metadataId, tree, database, iterStrategy);
            iter.setBoundsFilter(refBoundsFilter);
            return iter;
        default:
            throw new IllegalArgumentException(String.format("Invalid reference: %s", ref));
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 27 with RevObject

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

the class RevParse method resolveCommit.

/**
     * @param objectId
     * @return
     */
private RevCommit resolveCommit(ObjectId objectId) {
    final Optional<RevObject> object = command(RevObjectParse.class).setObjectId(objectId).call();
    checkArgument(object.isPresent(), "No object named %s could be found", objectId);
    final RevObject revObject = object.get();
    RevCommit commit;
    switch(revObject.getType()) {
        case COMMIT:
            commit = (RevCommit) revObject;
            break;
        case TAG:
            ObjectId commitId = ((RevTag) revObject).getCommitId();
            commit = command(RevObjectParse.class).setObjectId(commitId).call(RevCommit.class).get();
            break;
        default:
            throw new IllegalArgumentException(String.format("%s did not resolve to a commit or tag: %s", objectId, revObject.getType()));
    }
    return commit;
}
Also used : RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 28 with RevObject

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

the class CherryPickOpTest method testCherryPickWithConflicts.

@Test
public void testCherryPickWithConflicts() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    // create branch1, checkout and add a commit
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insert(points2);
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insertAndAdd(points1Modified);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource(Ref.MASTER).call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insert(points1ModifiedB);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).call();
    try {
        geogig.command(CherryPickOp.class).setCommit(Suppliers.ofInstance(branchCommit.getId())).call();
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("conflict in Points/Points.1"));
    }
    Optional<Ref> cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
    assertTrue(cherrypickHead.isPresent());
    // check that unconflicted changes are in index and working tree
    Optional<RevObject> pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
    assertTrue(pts2.isPresent());
    assertEquals(RevFeatureBuilder.build(points2), pts2.get());
    pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
    assertTrue(pts2.isPresent());
    assertEquals(RevFeatureBuilder.build(points2), pts2.get());
    // solve and commit
    Feature points1Solved = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insert(points1Solved);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setCommit(branchCommit).call();
    Optional<RevObject> ptsSolved = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP1)).call();
    assertTrue(pts2.isPresent());
    assertEquals(RevFeatureBuilder.build(points1Solved), ptsSolved.get());
    cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
    assertFalse(cherrypickHead.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) RevObject(org.locationtech.geogig.api.RevObject) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) 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) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 29 with RevObject

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

the class CloneOpTest method testClone.

@Test
public void testClone() throws Exception {
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(0);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
    // Make sure the local repository got all of the commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 30 with RevObject

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

the class CloneOpTest method testShallowClone.

@Test
public void testShallowClone() throws Exception {
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(2);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
    // Make sure the local repository got only 2 commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(2, logged.size());
    assertEquals(expected.get(0), logged.get(0));
    assertEquals(expected.get(1), logged.get(1));
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

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