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();
}
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");
}
}
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;
}
}
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());
}
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();
}
}
Aggregations