use of org.locationtech.geogig.repository.StagingArea in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitEmptyTreeOnNonEmptyRepo.
@Test
public void testCommitEmptyTreeOnNonEmptyRepo() throws Exception {
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
// insertAndAdd(lines1, lines2);
WorkingTree workingTree = geogig.getRepository().workingTree();
final String emptyTreeName = "emptyTree";
workingTree.createTypeTree(emptyTreeName, pointsType);
{
List<DiffEntry> unstaged = toList(workingTree.getUnstaged(null));
assertEquals(unstaged.toString(), 1, unstaged.size());
// assertEquals(NodeRef.ROOT, unstaged.get(0).newName());
assertEquals(emptyTreeName, unstaged.get(0).newName());
}
geogig.command(AddOp.class).call();
{
StagingArea index = geogig.getRepository().index();
List<DiffEntry> staged = toList(index.getStaged(null));
assertEquals(staged.toString(), 1, staged.size());
// assertEquals(NodeRef.ROOT, staged.get(0).newName());
assertEquals(emptyTreeName, staged.get(0).newName());
}
CommitOp commitCommand = geogig.command(CommitOp.class);
RevCommit commit = commitCommand.call();
assertNotNull(commit);
RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(RevTree.class).get();
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName).setParent(head).call();
assertTrue(ref.isPresent());
}
use of org.locationtech.geogig.repository.StagingArea in project GeoGig by boundlessgeo.
the class StatusOp method _call.
@Override
protected StatusSummary _call() {
WorkingTree workTree = workingTree();
StagingArea index = index();
StatusSummary summary = new StatusSummary();
summary.countStaged = index.countStaged(null).count();
summary.countUnstaged = workTree.countUnstaged(null).count();
summary.countConflicted = index.countConflicted(null);
if (summary.countStaged > 0) {
summary.staged = command(DiffIndex.class).setReportTrees(true);
}
if (summary.countUnstaged > 0) {
summary.unstaged = command(DiffWorkTree.class).setReportTrees(true);
}
if (summary.countConflicted > 0) {
summary.conflicts = command(ConflictsReadOp.class);
}
return summary;
}
use of org.locationtech.geogig.repository.StagingArea in project GeoGig by boundlessgeo.
the class OSMHistoryImport method parseGeometry.
/**
* @param primitive
* @param thisChangePointCache
* @return
*/
private Geometry parseGeometry(GeoGIG geogig, Primitive primitive, Map<Long, Coordinate> thisChangePointCache) {
if (primitive instanceof Relation) {
return null;
}
if (primitive instanceof Node) {
Optional<Point> location = ((Node) primitive).getLocation();
return location.orNull();
}
final Way way = (Way) primitive;
final ImmutableList<Long> nodes = way.getNodes();
StagingArea index = geogig.getRepository().index();
FeatureBuilder featureBuilder = new FeatureBuilder(NODE_REV_TYPE);
List<Coordinate> coordinates = Lists.newArrayList(nodes.size());
FindTreeChild findTreeChild = geogig.command(FindTreeChild.class);
findTreeChild.setIndex(true);
ObjectId rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(Ref.HEAD).call().get();
if (!rootTreeId.isNull()) {
RevTree headTree = geogig.command(RevObjectParse.class).setObjectId(rootTreeId).call(RevTree.class).get();
findTreeChild.setParent(headTree);
}
for (Long nodeId : nodes) {
Coordinate coord = thisChangePointCache.get(nodeId);
if (coord == null) {
String fid = String.valueOf(nodeId);
String path = NodeRef.appendChild(NODE_TYPE_NAME, fid);
Optional<org.locationtech.geogig.api.Node> ref = index.findStaged(path);
if (!ref.isPresent()) {
Optional<NodeRef> nodeRef = findTreeChild.setChildPath(path).call();
if (nodeRef.isPresent()) {
ref = Optional.of(nodeRef.get().getNode());
} else {
ref = Optional.absent();
}
}
if (ref.isPresent()) {
org.locationtech.geogig.api.Node nodeRef = ref.get();
RevFeature revFeature = index.getDatabase().getFeature(nodeRef.getObjectId());
String id = NodeRef.nodeFromPath(nodeRef.getName());
Feature feature = featureBuilder.build(id, revFeature);
Point p = (Point) ((SimpleFeature) feature).getAttribute("location");
if (p != null) {
coord = p.getCoordinate();
thisChangePointCache.put(Long.valueOf(nodeId), coord);
}
}
}
if (coord != null) {
coordinates.add(coord);
}
}
if (coordinates.size() < 2) {
return null;
}
return GEOMF.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
Aggregations