use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class LocalMappedRemoteRepo method pushSparseCommit.
/**
* This function takes all of the changes introduced by a commit on the sparse repository and
* creates a new commit on the full repository with those changes.
*
* @param commitId the commit id of commit from the sparse repository
* @param from the sparse repository
* @param to the full repository
*/
protected void pushSparseCommit(ObjectId commitId) {
Repository from = localRepository;
Repository to = remoteGeoGig.getRepository();
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 the sparse 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();
LocalCopyingDiffIterator changes = new LocalCopyingDiffIterator(diffIter, from, to);
RevTree rootTree = RevTree.EMPTY;
if (newParents.size() > 0) {
ObjectId mappedCommit = newParents.get(0);
Optional<ObjectId> treeId = to.command(ResolveTreeish.class).setTreeish(mappedCommit).call();
if (treeId.isPresent()) {
rootTree = to.getTree(treeId.get());
}
}
// Create new commit
ObjectId newTreeId = to.command(WriteTree.class).setOldRoot(Suppliers.ofInstance(rootTree)).setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) changes)).call();
CommitBuilder builder = new CommitBuilder(commit);
builder.setParentIds(newParents);
builder.setTreeId(newTreeId);
RevCommit mapped = builder.build();
to.objectDatabase().put(mapped);
from.graphDatabase().map(commit.getId(), mapped.getId());
from.graphDatabase().map(mapped.getId(), commit.getId());
}
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class FilteredDiffIterator method computeNext.
/**
* Compute the next {@link DiffEntry} that matches our {@link RepositoryFilter}.
*/
protected DiffEntry computeNext() {
while (source.hasNext()) {
DiffEntry input = source.next();
// DiffTree) that doesn't report tree changes even is setReportTrees(true) was set.
if (input.isChange() && input.getOldObject().getType().equals(TYPE.TREE)) {
continue;
}
NodeRef oldObject = filter(input.getOldObject());
NodeRef newObject;
if (oldObject != null) {
newObject = input.getNewObject();
if (newObject != null) {
// we are tracking this object, but we still need to process the new object
RevObject object = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getNode().getObjectId()).call().get();
RevObject metadata = null;
if (newObject.getMetadataId() != ObjectId.NULL) {
metadata = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call().get();
}
processObject(object);
processObject(metadata);
}
} else {
newObject = filter(input.getNewObject());
}
if (oldObject == null && newObject == null) {
filtered = true;
continue;
}
return new DiffEntry(oldObject, newObject);
}
return endOfData();
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class DiffTreeTest method testTreePathFiltering.
@Test
public void testTreePathFiltering() {
ObjectDatabase db = geogit.getContext().objectDatabase();
RevTree tree1 = tree(100, db);
RevTree tree2 = tree(50, db);
RevTree root = createRoot(db, tree1, tree2);
List<String> pathFilters = ImmutableList.of("tree1");
diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId()).setPathFilter(pathFilters);
List<DiffEntry> diffs = ImmutableList.copyOf(diffTree.call());
assertEquals(tree1.size(), diffs.size());
pathFilters = ImmutableList.of("tree2");
diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId()).setPathFilter(pathFilters);
diffs = ImmutableList.copyOf(diffTree.call());
assertEquals(tree2.size(), diffs.size());
pathFilters = ImmutableList.of("tree1/1", "tree1/2", "tree1/3", "tree1/4", "tree2/2", "tree2/3", "tree2/10");
diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId()).setPathFilter(pathFilters);
diffs = ImmutableList.copyOf(diffTree.call());
assertEquals(pathFilters.size(), diffs.size());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class CreatePatchOpTest method testCreatePatchModifyFeatureType.
@Test
public void testCreatePatchModifyFeatureType() throws Exception {
DiffOp op = geogig.command(DiffOp.class).setReportTrees(true);
insertAndAdd(points1, points2);
geogig.getRepository().workingTree().updateTypeTree(pointsName, modifiedPointsType);
Iterator<DiffEntry> diffs = op.call();
Patch patch = geogig.command(CreatePatchOp.class).setDiffs(diffs).call();
assertEquals(1, patch.getAlteredTrees().size());
assertEquals(RevFeatureTypeImpl.build(pointsType).getId(), patch.getAlteredTrees().get(0).getOldFeatureType());
assertEquals(RevFeatureTypeImpl.build(modifiedPointsType).getId(), patch.getAlteredTrees().get(0).getNewFeatureType());
assertEquals(2, patch.getFeatureTypes().size());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class DiffOpTest method testReportTreesEmptyTree.
@Test
public void testReportTreesEmptyTree() throws Exception {
WorkingTree workingTree = geogig.getRepository().workingTree();
workingTree.createTypeTree(linesName, linesType);
List<DiffEntry> difflist = toList(diffOp.setReportTrees(true).setOldVersion(ObjectId.NULL).setNewVersion(Ref.WORK_HEAD).call());
assertNotNull(difflist);
assertEquals(1, difflist.size());
DiffEntry de = difflist.get(0);
assertNull(de.getOldObject());
assertNotNull(de.getNewObject());
assertEquals(linesName, de.newPath());
assertEquals(DiffEntry.ChangeType.ADDED, de.changeType());
assertEquals(ObjectId.NULL, de.oldObjectId());
assertFalse(de.getNewObject().getMetadataId().isNull());
}
Aggregations