use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class FindOrCreateSubtree method _call.
/**
* Executes the command.
*
* @return the subtree if it was found, or a new one if it wasn't
*/
@Override
protected RevTree _call() {
checkNotNull(parentSupplier, "parent");
checkNotNull(childPath, "childPath");
ObjectId subtreeId;
if (parentSupplier.get().isPresent()) {
RevTree parent = parentSupplier.get().get();
Optional<NodeRef> treeChildRef = command(FindTreeChild.class).setIndex(indexDb).setParentPath(parentPath).setChildPath(childPath).setParent(Suppliers.ofInstance(parent)).call();
if (treeChildRef.isPresent()) {
NodeRef treeRef = treeChildRef.get();
if (!TYPE.TREE.equals(treeRef.getType())) {
throw new IllegalArgumentException("Object exists as child of tree " + parent.getId() + " but is not a tree: " + treeChildRef);
}
subtreeId = treeRef.objectId();
} else {
subtreeId = RevTree.EMPTY_TREE_ID;
}
} else {
subtreeId = RevTree.EMPTY_TREE_ID;
}
if (RevTree.EMPTY_TREE_ID.equals(subtreeId)) {
return RevTree.EMPTY;
}
ObjectDatabase target = indexDb ? stagingDatabase() : objectDatabase();
RevTree tree = target.getTree(subtreeId);
return tree;
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class CloneOpTest method testClone.
@Test
public void testClone() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got all of the commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class CloneOpTest method testShallowClone.
@Test
public void testShallowClone() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(2);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got only 2 commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(2, logged.size());
assertEquals(expected.get(0), logged.get(0));
assertEquals(expected.get(1), logged.get(1));
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class RevCommitSerializationTest method testCommitRoundTrippin.
@Test
public void testCommitRoundTrippin() throws Exception {
long currentTime = System.currentTimeMillis();
int timeZoneOffset = TimeZone.getDefault().getOffset(currentTime);
CommitBuilder builder = new CommitBuilder();
String author = "groldan";
builder.setAuthor(author);
String authorEmail = "groldan@boundlessgeo.com";
builder.setAuthorEmail(authorEmail);
builder.setAuthorTimestamp(currentTime);
builder.setAuthorTimeZoneOffset(timeZoneOffset);
String committer = "mleslie";
builder.setCommitter(committer);
String committerEmail = "mleslie@boundlessgeo.com";
builder.setCommitterEmail(committerEmail);
builder.setCommitterTimestamp(currentTime);
builder.setCommitterTimeZoneOffset(timeZoneOffset);
ObjectId treeId = ObjectId.forString("Fake tree");
builder.setTreeId(treeId);
ObjectId parent1 = ObjectId.forString("Parent 1 of fake commit");
ObjectId parent2 = ObjectId.forString("Parent 2 of fake commit");
List<ObjectId> parents = Arrays.asList(parent1, parent2);
builder.setParentIds(parents);
RevCommit cmtIn = builder.build();
assertNotNull(cmtIn);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectWriter<RevCommit> write = factory.createObjectWriter(TYPE.COMMIT);
write.write(cmtIn, bout);
// System.err.println(bout);
byte[] bytes = bout.toByteArray();
assertTrue(bytes.length > 0);
ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
ObjectReader<RevCommit> read = factory.createCommitReader();
RevCommit cmtOut = read.read(cmtIn.getId(), bin);
assertEquals(treeId, cmtOut.getTreeId());
assertEquals(parents, cmtOut.getParentIds());
assertEquals(author, cmtOut.getAuthor().getName().get());
assertEquals(authorEmail, cmtOut.getAuthor().getEmail().get());
assertEquals(committer, cmtOut.getCommitter().getName().get());
assertEquals(committerEmail, cmtOut.getCommitter().getEmail().get());
assertEquals(currentTime, cmtOut.getCommitter().getTimestamp());
assertEquals(timeZoneOffset, cmtOut.getCommitter().getTimeZoneOffset());
assertEquals(currentTime, cmtOut.getAuthor().getTimestamp());
assertEquals(timeZoneOffset, cmtOut.getAuthor().getTimeZoneOffset());
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class CheckoutOpTest method testCheckoutPathFilter.
@Test
public void testCheckoutPathFilter() throws Exception {
ObjectId points1Id = insertAndAdd(points1);
geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
insert(points1_modified);
CheckoutResult result = geogig.command(CheckoutOp.class).addPath("Points/Points.1").call();
Optional<RevTree> workTree = geogig.command(RevObjectParse.class).setObjectId(result.getNewTree()).call(RevTree.class);
Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.1").call();
assertEquals(points1Id, nodeRef.get().getNode().getObjectId());
}
Aggregations