use of org.locationtech.geogig.api.RevObject 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.RevObject in project GeoGig by boundlessgeo.
the class AbstractObjectDatabase method writeObject.
protected void writeObject(RevObject object, OutputStream target) {
ObjectWriter<RevObject> writer = serializationFactory.createObjectWriter(object.getType());
LZFOutputStream cOut = new LZFOutputStream(target);
try {
writer.write(object, cOut);
} catch (IOException e) {
throw Throwables.propagate(e);
} finally {
try {
cOut.flush();
cOut.close();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
// int size = ((ByteArrayOutputStream) target).size();
// System.err.printf("%d,%s,%s\n", size, object.getId(), object.getType());
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class PostOrderIterator method computeNext.
@Override
protected RevObject computeNext() {
while (!toVisit.isEmpty()) {
List<ObjectId> currentList = toVisit.get(0);
if (currentList.isEmpty()) {
// No more ids at this depth - pop a level off of the stack and switch to "visiting"
// mode
enqueue = false;
toVisit.remove(0);
} else {
if (enqueue) {
// We're building up a list of objects to visit, so add all the reachable
// objects from here to the front of the toVisit stack
final ObjectId id = currentList.get(0);
final RevObject object = database.get(id);
final List<ObjectId> next = new ArrayList<ObjectId>();
successors.findSuccessors(object, next);
toVisit.add(0, next);
} else {
// We just visited a node, so switch back to enqueuing mode in order to make
// sure the successors of the next one at this depth are visited.
enqueue = true;
final ObjectId id = currentList.remove(0);
if (successors.previsit(id)) {
return database.get(id);
}
}
}
}
// when the toVisit list becomes empty, we are done
return endOfData();
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class AbstractObjectDatabase method putAll.
/**
* This default implementation calls {@link #putInternal(ObjectId, byte[])} for each object;
* subclasses may override if appropriate.
*/
@Override
public void putAll(Iterator<? extends RevObject> objects, final BulkOpListener listener) {
ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
while (objects.hasNext()) {
RevObject object = objects.next();
rawOut.reset();
writeObject(object, rawOut);
final byte[] rawData = rawOut.toByteArray();
final ObjectId id = object.getId();
final boolean added = putInternal(id, rawData);
if (added) {
listener.inserted(object.getId(), rawData.length);
} else {
listener.found(object.getId(), null);
}
}
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class HashObject method _call.
/**
* Hashes a RevObject using a SHA1 hasher.
*
* @return a new ObjectId created from the hash of the RevObject.
*/
@Override
protected ObjectId _call() {
Preconditions.checkState(object != null, "Object has not been set.");
final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
@SuppressWarnings("unchecked") final Funnel<RevObject> funnel = (Funnel<RevObject>) FUNNELS[object.getType().value()];
funnel.funnel(object, hasher);
final byte[] rawKey = hasher.hash().asBytes();
final ObjectId id = ObjectId.createNoClone(rawKey);
return id;
}
Aggregations