Search in sources :

Example 46 with RevCommit

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

the class ResponseWriter method writeBlameReport.

/**
     * Writes the response for the blame operation.
     * 
     * @param report - the result of the blame operation
     * @throws XMLStreamException
     */
public void writeBlameReport(BlameReport report) throws XMLStreamException {
    out.writeStartElement("Blame");
    Map<String, ValueAndCommit> changes = report.getChanges();
    Iterator<String> iter = changes.keySet().iterator();
    while (iter.hasNext()) {
        String attrib = iter.next();
        ValueAndCommit valueAndCommit = changes.get(attrib);
        RevCommit commit = valueAndCommit.commit;
        Optional<?> value = valueAndCommit.value;
        out.writeStartElement("Attribute");
        writeElement("name", attrib);
        writeElement("value", TextValueSerializer.asString(Optional.fromNullable((Object) value.orNull())));
        writeCommit(commit, "commit", null, null, null);
        out.writeEndElement();
    }
    out.writeEndElement();
}
Also used : ValueAndCommit(org.locationtech.geogig.api.porcelain.ValueAndCommit) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 47 with RevCommit

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

the class ResponseWriter method writeCommits.

/**
     * Writes a set of {@link RevCommit}s to the stream.
     * 
     * @param entries an iterator for the RevCommits to write
     * @param elementsPerPage the number of commits per page
     * @param returnRange only return the range if true
     * @throws XMLStreamException
     */
public void writeCommits(Iterator<RevCommit> entries, int elementsPerPage, boolean returnRange) throws XMLStreamException {
    int counter = 0;
    RevCommit lastCommit = null;
    if (returnRange) {
        if (entries.hasNext()) {
            lastCommit = entries.next();
            writeCommit(lastCommit, "untilCommit", null, null, null);
            counter++;
        }
    }
    while (entries.hasNext() && (returnRange || counter < elementsPerPage)) {
        lastCommit = entries.next();
        if (!returnRange) {
            writeCommit(lastCommit, "commit", null, null, null);
        }
        counter++;
    }
    if (returnRange) {
        if (lastCommit != null) {
            writeCommit(lastCommit, "sinceCommit", null, null, null);
        }
        writeElement("numCommits", Integer.toString(counter));
    }
    if (entries.hasNext()) {
        writeElement("nextPage", "true");
    }
}
Also used : RevCommit(org.locationtech.geogig.api.RevCommit)

Example 48 with RevCommit

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

the class CatWebOp method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    Preconditions.checkArgument(object != null && !object.equals(ObjectId.NULL));
    final Context geogig = this.getCommandLocator(context);
    Preconditions.checkState(geogig.stagingDatabase().exists(object));
    final RevObject revObject = geogig.stagingDatabase().get(object);
    switch(revObject.getType()) {
        case COMMIT:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeCommit((RevCommit) revObject, "commit", null, null, null);
                    out.finish();
                }
            });
            break;
        case TREE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeTree((RevTree) revObject, "tree");
                    out.finish();
                }
            });
            break;
        case FEATURE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeFeature((RevFeature) revObject, "feature");
                    out.finish();
                }
            });
            break;
        case FEATURETYPE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeFeatureType((RevFeatureType) revObject, "featuretype");
                    out.finish();
                }
            });
            break;
        case TAG:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeTag((RevTag) revObject, "tag");
                    out.finish();
                }
            });
            break;
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RevFeature(org.locationtech.geogig.api.RevFeature) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 49 with RevCommit

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

use of org.locationtech.geogig.api.RevCommit 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)

Aggregations

RevCommit (org.locationtech.geogig.api.RevCommit)291 Test (org.junit.Test)212 ObjectId (org.locationtech.geogig.api.ObjectId)109 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)107 LogOp (org.locationtech.geogig.api.porcelain.LogOp)86 Ref (org.locationtech.geogig.api.Ref)71 Feature (org.opengis.feature.Feature)52 NodeRef (org.locationtech.geogig.api.NodeRef)47 ArrayList (java.util.ArrayList)44 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)44 RevTree (org.locationtech.geogig.api.RevTree)36 SymRef (org.locationtech.geogig.api.SymRef)33 RefParse (org.locationtech.geogig.api.plumbing.RefParse)33 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)31 RevObject (org.locationtech.geogig.api.RevObject)30 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)30 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)30 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)26 LinkedList (java.util.LinkedList)24 AddOp (org.locationtech.geogig.api.porcelain.AddOp)21