use of org.locationtech.geogig.storage.ObjectInserter in project GeoGig by boundlessgeo.
the class IndexTest method testWriteTree.
@Test
public void testWriteTree() throws Exception {
insertAndAdd(points1);
insertAndAdd(lines1);
// this new root tree must exist on the repo db, but is not set as the current head. In
// fact, it is headless, as there's no commit pointing to it. CommitOp does that.
ObjectId newRootTreeId = geogig.command(WriteTree.class).setOldRoot(tree(repo.getHead().get().getObjectId())).call();
assertNotNull(newRootTreeId);
assertFalse(repo.getRootTreeId().equals(newRootTreeId));
// but the index staged root shall be pointing to it
// assertEquals(newRootTreeId, index.getStaged().getId());
RevTree tree = repo.getTree(newRootTreeId);
// assertEquals(2, tree.size().intValue());
String path = appendChild(pointsName, points1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
path = appendChild(linesName, lines1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
// simulate a commit so the repo head points to this new tree
ObjectInserter objectInserter = repo.newObjectInserter();
List<ObjectId> parents = ImmutableList.of();
RevCommit commit = new CommitBuilder(geogig.getPlatform()).setTreeId(newRootTreeId).setParentIds(parents).build();
ObjectId commitId = commit.getId();
objectInserter.insert(commit);
Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
assertTrue(newHead.isPresent());
WorkingTree workTree = repo.workingTree();
workTree.delete(linesName, lines1.getIdentifier().getID());
geogig.command(AddOp.class).call();
// newRootTreeId
newRootTreeId = geogig.command(WriteTree2.class).setOldRoot(tree(newRootTreeId)).call();
// =
// index.writeTree(newRootTreeId,
// new
// NullProgressListener());
assertNotNull(newRootTreeId);
assertFalse(repo.getRootTreeId().equals(newRootTreeId));
tree = repo.getTree(newRootTreeId);
path = appendChild(pointsName, points1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
path = appendChild(linesName, lines1.getIdentifier().getID());
assertFalse(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
}
use of org.locationtech.geogig.storage.ObjectInserter in project GeoGig by boundlessgeo.
the class IndexTest method testWriteTree2.
@Test
public void testWriteTree2() throws Exception {
// insert and commit feature1_1
final ObjectId oId1_1 = insertAndAdd(points1);
final ObjectId newRepoTreeId1;
{
newRepoTreeId1 = geogig.command(WriteTree2.class).setOldRoot(tree(repo.getHead().get().getObjectId())).call();
// assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId1);
RevTree newRepoTree = repo.getTree(newRepoTreeId1);
System.err.println("++++++++++ new repo tree 1: " + newRepoTreeId1 + " ++++++++++++");
// check feature1_1 is there
assertEquals(oId1_1, repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)).get().getObjectId());
}
// insert and add (stage) points2, points3, and lines1
final ObjectId oId1_2 = insertAndAdd(points2);
final ObjectId oId1_3 = insertAndAdd(points3);
final ObjectId oId2_1 = insertAndAdd(lines1);
{
// simulate a commit so the repo head points to this new tree
ObjectInserter objectInserter = repo.newObjectInserter();
List<ObjectId> parents = ImmutableList.of();
RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId1).setParentIds(parents).build();
ObjectId commitId = commit.getId();
objectInserter.insert(commit);
Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
assertTrue(newHead.isPresent());
}
final ObjectId newRepoTreeId2;
{
// write comparing the the previously generated tree instead of the repository HEAD, as
// it was not updated (no commit op was performed)
newRepoTreeId2 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId1)).call();
// assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId2);
System.err.println("++++++++ new root 2:" + newRepoTreeId2 + " ++++++++++");
RevTree newRepoTree = repo.getTree(newRepoTreeId2);
// check feature1_2, feature1_2 and feature2_1
Optional<Node> treeChild;
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)));
assertEquals(oId1_2, treeChild.get().getObjectId());
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)));
assertEquals(oId1_3, treeChild.get().getObjectId());
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(linesName, idL1)));
assertEquals(oId2_1, treeChild.get().getObjectId());
// as well as feature1_1 from the previous commit
assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)));
assertEquals(oId1_1, treeChild.get().getObjectId());
}
{
// simulate a commit so the repo head points to this new tree
ObjectInserter objectInserter = repo.newObjectInserter();
List<ObjectId> parents = ImmutableList.of();
RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId2).setParentIds(parents).build();
ObjectId commitId = commit.getId();
objectInserter.insert(commit);
Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
assertTrue(newHead.isPresent());
}
// delete feature1_1, feature1_3, and feature2_1
assertTrue(deleteAndAdd(points1));
assertTrue(deleteAndAdd(points3));
assertTrue(deleteAndAdd(lines1));
// and insert feature2_2
final ObjectId oId2_2 = insertAndAdd(lines2);
final ObjectId newRepoTreeId3;
{
// write comparing the the previously generated tree instead of the repository HEAD, as
// it was not updated (no commit op was performed)
newRepoTreeId3 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId2)).call();
// assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId3);
System.err.println("++++++++ new root 3:" + newRepoTreeId3 + " ++++++++++");
RevTree newRepoTree = repo.getTree(newRepoTreeId3);
// and check only feature1_2 and feature2_2 remain
assertFalse(repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)).isPresent());
assertFalse(repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)).isPresent());
assertFalse(repo.getTreeChild(newRepoTree, appendChild(linesName, idL3)).isPresent());
assertEquals(oId1_2, repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)).get().getObjectId());
assertEquals(oId2_2, repo.getTreeChild(newRepoTree, appendChild(linesName, idL2)).get().getObjectId());
}
}
Aggregations