use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class GeoGigAPI method getUnstagedFeatures.
public Feature[] getUnstagedFeatures(String path, boolean noDeletions) {
Iterator<DiffEntry> diffs = repository.workingTree().getUnstaged(path);
List<Feature> list = Lists.newArrayList();
while (diffs.hasNext()) {
DiffEntry diff = diffs.next();
if (!diff.changeType().equals(ChangeType.REMOVED) || !noDeletions) {
RevFeature revFeature = repository.command(RevObjectParse.class).setObjectId(diff.newObjectId()).call(RevFeature.class).get();
RevFeatureType revFeatureType = repository.command(RevObjectParse.class).setObjectId(diff.getNewObject().getMetadataId()).call(RevFeatureType.class).get();
FeatureBuilder builder = new FeatureBuilder(revFeatureType);
list.add(builder.build(diff.getNewObject().name(), revFeature));
}
}
return list.toArray(new Feature[0]);
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class DiffTreeTest method testBoundsFilteringReprojecting.
@Test
public void testBoundsFilteringReprojecting() throws Exception {
ObjectDatabase db = geogit.getContext().objectDatabase();
RevTree tree1 = tree(1000, db);
RevTree tree2 = tree(50, db);
RevTree root = createRoot(db, tree1, tree2);
CoordinateReferenceSystem nativeCrs = revtype.type().getCoordinateReferenceSystem();
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:4326", true);
ReferencedEnvelope nativeFilter = new ReferencedEnvelope(49.9, 51.1, 49.9, 51.1, nativeCrs);
ReferencedEnvelope queryFilter = nativeFilter.transform(queryCrs, true);
List<DiffEntry> diffs;
diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
diffTree.setBoundsFilter(queryFilter);
diffs = ImmutableList.copyOf(diffTree.call());
assertEquals(2, diffs.size());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class DiffTreeTest method testBoundsFiltering.
@Test
public void testBoundsFiltering() {
ObjectDatabase db = geogit.getContext().objectDatabase();
RevTree tree1 = tree(1000, db);
RevTree tree2 = tree(50, db);
RevTree root = createRoot(db, tree1, tree2);
CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
ReferencedEnvelope filter;
List<DiffEntry> diffs;
diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
filter = new ReferencedEnvelope(50, 51, 50, 51, crs);
diffTree.setBoundsFilter(filter);
diffs = ImmutableList.copyOf(diffTree.call());
assertEquals(2, diffs.size());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class HttpMappedRemoteRepo method pushSparseCommit.
/**
* Pushes a sparse commit to a remote repository and updates all mappings.
*
* @param commitId the commit to push
*/
@Override
protected void pushSparseCommit(ObjectId commitId) {
Repository from = localRepository;
Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId).call();
if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
RevCommit commit = (RevCommit) object.get();
ObjectId parent = ObjectId.NULL;
List<ObjectId> newParents = new LinkedList<ObjectId>();
for (int i = 0; i < commit.getParentIds().size(); i++) {
ObjectId parentId = commit.getParentIds().get(i);
if (i != 0) {
Optional<ObjectId> commonAncestor = from.command(FindCommonAncestor.class).setLeftId(commit.getParentIds().get(0)).setRightId(parentId).call();
if (commonAncestor.isPresent()) {
if (from.command(CheckSparsePath.class).setStart(parentId).setEnd(commonAncestor.get()).call()) {
// This should be the base commit to preserve changes that were filtered
// out.
newParents.add(0, from.graphDatabase().getMapping(parentId));
continue;
}
}
}
newParents.add(from.graphDatabase().getMapping(parentId));
}
if (newParents.size() > 0) {
parent = from.graphDatabase().getMapping(newParents.get(0));
}
Iterator<DiffEntry> diffIter = from.command(DiffOp.class).setNewVersion(commitId).setOldVersion(parent).setReportTrees(true).call();
// connect and send packed changes
final URL resourceURL;
try {
resourceURL = new URL(repositoryURL.toString() + "/repo/applychanges");
} catch (MalformedURLException e) {
throw Throwables.propagate(e);
}
final HttpURLConnection connection;
final OutputStream out;
try {
connection = (HttpURLConnection) resourceURL.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
out = connection.getOutputStream();
// pack the commit object
final ObjectSerializingFactory factory = DataStreamSerializationFactoryV1.INSTANCE;
final ObjectWriter<RevCommit> commitWriter = factory.createObjectWriter(TYPE.COMMIT);
commitWriter.write(commit, out);
// write the new parents
out.write(newParents.size());
for (ObjectId parentId : newParents) {
out.write(parentId.getRawValue());
}
// pack the changes
BinaryPackedChanges changes = new BinaryPackedChanges(from);
changes.write(out, diffIter);
} catch (IOException e) {
throw Throwables.propagate(e);
}
final InputStream in;
try {
in = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
String line = rd.readLine();
if (line != null) {
ObjectId remoteCommitId = ObjectId.valueOf(line);
from.graphDatabase().map(commit.getId(), remoteCommitId);
from.graphDatabase().map(remoteCommitId, commit.getId());
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class RemoveOp method _call.
/**
* @see java.util.concurrent.Callable#call()
*/
protected WorkingTree _call() {
// Check that all paths are valid and exist
for (String pathToRemove : pathsToRemove) {
NodeRef.checkValidPath(pathToRemove);
Optional<NodeRef> node;
node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
List<Conflict> conflicts = index().getConflicted(pathToRemove);
if (conflicts.size() > 0) {
for (Conflict conflict : conflicts) {
stagingDatabase().removeConflict(null, conflict.getPath());
}
} else {
Preconditions.checkArgument(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
}
}
// separate trees from features an delete accordingly
for (String pathToRemove : pathsToRemove) {
Optional<NodeRef> node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
if (!node.isPresent()) {
continue;
}
switch(node.get().getType()) {
case TREE:
workingTree().delete(pathToRemove);
break;
case FEATURE:
String parentPath = NodeRef.parentPath(pathToRemove);
String name = node.get().name();
workingTree().delete(parentPath, name);
break;
default:
break;
}
final long numChanges = workingTree().countUnstaged(pathToRemove).count();
Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathToRemove);
index().stage(getProgressListener(), unstaged, numChanges);
}
return workingTree();
}
Aggregations