Search in sources :

Example 1 with ObjectId

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

the class MergeBase method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(commits.size() == 2, "Two commit references must be provided");
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)).call();
    checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object.");
    checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit");
    Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)).call();
    checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object.");
    checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit");
    Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class).setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call();
    checkParameter(ancestor.isPresent(), "No common ancestor was found.");
    console.print(ancestor.get().toString());
}
Also used : ConsoleReader(jline.console.ConsoleReader) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 2 with ObjectId

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

the class RevList method runInternal.

/**
     * Executes the revlist command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(!args.commits.isEmpty(), "No starting commit provided");
    geogig = cli.getGeogig();
    LogOp op = geogig.command(LogOp.class).setTopoOrder(args.topo).setFirstParentOnly(args.firstParent);
    for (String commit : args.commits) {
        if (commit.contains("..")) {
            checkParameter(args.commits.size() == 1, "Only one value accepted when using <since>..<until> syntax");
            List<String> sinceUntil = ImmutableList.copyOf((Splitter.on("..").split(commit)));
            checkParameter(sinceUntil.size() == 2 || sinceUntil.size() == 1, "Invalid refSpec format, expected [<commit> ...]|[<since>..<until>]: %s", commit);
            String sinceRefSpec;
            String untilRefSpec;
            if (sinceUntil.size() == 1) {
                // just until was given
                sinceRefSpec = null;
                untilRefSpec = sinceUntil.get(0);
            } else {
                sinceRefSpec = sinceUntil.get(0);
                untilRefSpec = sinceUntil.get(1);
            }
            if (sinceRefSpec != null) {
                Optional<ObjectId> since;
                since = geogig.command(RevParse.class).setRefSpec(sinceRefSpec).call();
                checkParameter(since.isPresent(), "Object not found '%s'", sinceRefSpec);
                op.setSince(since.get());
            }
            if (untilRefSpec != null) {
                Optional<ObjectId> until;
                until = geogig.command(RevParse.class).setRefSpec(untilRefSpec).call();
                checkParameter(until.isPresent(), "Object not found '%s'", sinceRefSpec);
                op.setUntil(until.get());
            }
        } else {
            Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit).call();
            checkParameter(commitId.isPresent(), "Object not found '%s'", commit);
            checkParameter(geogig.getRepository().commitExists(commitId.get()), "%s does not resolve to a commit", commit);
            op.addCommit(commitId.get());
        }
    }
    if (args.author != null && !args.author.isEmpty()) {
        op.setAuthor(args.author);
    }
    if (args.committer != null && !args.committer.isEmpty()) {
        op.setCommiter(args.committer);
    }
    if (args.skip != null) {
        op.setSkip(args.skip.intValue());
    }
    if (args.limit != null) {
        op.setLimit(args.limit.intValue());
    }
    if (args.since != null || args.until != null) {
        Date since = new Date(0);
        Date until = new Date();
        if (args.since != null) {
            since = new Date(geogig.command(ParseTimestamp.class).setString(args.since).call());
        }
        if (args.until != null) {
            until = new Date(geogig.command(ParseTimestamp.class).setString(args.until).call());
        }
        op.setTimeRange(new Range<Date>(Date.class, since, until));
    }
    if (!args.pathNames.isEmpty()) {
        for (String s : args.pathNames) {
            op.addPath(s);
        }
    }
    Iterator<RevCommit> log = op.call();
    console = cli.getConsole();
    RawPrinter printer = new RawPrinter(args.changed);
    while (log.hasNext()) {
        printer.print(log.next());
        console.flush();
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) LogOp(org.locationtech.geogig.api.porcelain.LogOp) Date(java.util.Date) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 3 with ObjectId

use of org.locationtech.geogig.api.ObjectId 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 4 with ObjectId

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

the class AbstractObjectDatabase method put.

@Override
public boolean put(final RevObject object) {
    Preconditions.checkNotNull(object);
    Preconditions.checkArgument(!object.getId().isNull(), "ObjectId is NULL %s", object);
    ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
    writeObject(object, rawOut);
    final ObjectId id = object.getId();
    final byte[] rawData = rawOut.toByteArray();
    final boolean inserted = putInternal(id, rawData);
    return inserted;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with ObjectId

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

the class AbstractObjectDatabase method lookUp.

/**
     * Searches the database for {@link ObjectId}s that match the given partial id.
     * 
     * @param partialId the partial id to search for
     * @return a list of matching results
     * @see org.locationtech.geogig.storage.ObjectDatabase#lookUp(java.lang.String)
     */
@Override
public List<ObjectId> lookUp(final String partialId) {
    Preconditions.checkNotNull(partialId);
    byte[] raw = ObjectId.toRaw(partialId);
    List<ObjectId> baseResults = lookUpInternal(raw);
    // the lookup, we need to filter the list further.
    if (partialId.length() % 2 != 0) {
        Iterator<ObjectId> listIterator = baseResults.iterator();
        while (listIterator.hasNext()) {
            ObjectId result = listIterator.next();
            if (!result.toString().startsWith(partialId)) {
                listIterator.remove();
            }
        }
    }
    return baseResults;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22