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