use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.
the class WriteTree2 method handleDeletedTrees.
private void handleDeletedTrees(TreeDifference treeDifference, Set<String> ignoreList) {
SortedSet<NodeRef> deletes = treeDifference.findDeletes();
for (NodeRef ref : deletes) {
String path = ref.path();
if (ignoreList.contains(path)) {
continue;
}
ignoreList.add(path);
if (!filterMatchesOrIsParent(path)) {
if (filterApplies(path, treeDifference.getRightTree())) {
// can't optimize
RevTree newTree = applyChanges(ref, null);
Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
MutableTree leftTree = treeDifference.getLeftTree();
leftTree.forceChild(ref.getParentPath(), newNode);
}
} else {
MutableTree leftTree = treeDifference.getLeftTree();
leftTree.removeChild(path);
}
}
}
use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.
the class WriteTree2 method handleNewTrees.
private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) {
SortedSet<NodeRef> newTrees = treeDifference.findNewTrees();
for (NodeRef ref : newTrees) {
final String path = ref.path();
if (ignoreList.contains(path)) {
continue;
}
ignoreList.add(path);
if (!filterMatchesOrIsParent(path)) {
MutableTree rightTree = treeDifference.getRightTree();
if (filterApplies(path, rightTree)) {
// can't optimize
RevTree newTree = applyChanges(null, ref);
Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
MutableTree leftTree = treeDifference.getLeftTree();
leftTree.forceChild(ref.getParentPath(), newNode);
}
} else {
LOGGER.trace("Creating new tree {}", path);
deepMove(ref.getNode());
MutableTree leftTree = treeDifference.getLeftTree();
String parentPath = ref.getParentPath();
Node node = ref.getNode();
leftTree.setChild(parentPath, node);
}
}
}
use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.
the class WriteTree2 method handlePureMetadataChanges.
private void handlePureMetadataChanges(TreeDifference treeDifference, Set<String> ignoreList) {
Map<NodeRef, NodeRef> pureMetadataChanges = treeDifference.findPureMetadataChanges();
for (Map.Entry<NodeRef, NodeRef> e : pureMetadataChanges.entrySet()) {
NodeRef newValue = e.getValue();
String treePath = newValue.path();
if (ignoreList.contains(treePath)) {
continue;
}
ignoreList.add(treePath);
if (!filterMatchesOrIsParent(treePath)) {
// filter doesn't apply to the changed tree
continue;
}
deepMove(newValue.getMetadataId());
MutableTree leftTree = treeDifference.getLeftTree();
leftTree.setChild(newValue.getParentPath(), newValue.getNode());
}
}
use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.
the class WriteTree2 method handleRemainingDifferences.
private void handleRemainingDifferences(TreeDifference treeDifference, Set<String> ignoreList) {
// old/new refs to trees that have changed and apply to the pathFilters, deepest paths first
final SortedMap<NodeRef, NodeRef> changedTrees = treeDifference.findChanges();
// filterChanges(changedTrees);
final SortedMap<NodeRef, NodeRef> filteredChangedTrees = changedTrees;
for (Map.Entry<NodeRef, NodeRef> changedTreeRefs : filteredChangedTrees.entrySet()) {
NodeRef leftTreeRef = changedTreeRefs.getKey();
NodeRef rightTreeRef = changedTreeRefs.getValue();
String newPath = rightTreeRef.path();
if (ignoreList.contains(newPath)) {
continue;
}
if (!filterApplies(newPath, treeDifference.getRightTree())) {
continue;
}
ignoreList.add(newPath);
RevTree tree = applyChanges(leftTreeRef, rightTreeRef);
Envelope bounds = SpatialOps.boundsOf(tree);
Node newTreeNode = Node.create(rightTreeRef.name(), tree.getId(), rightTreeRef.getMetadataId(), TYPE.TREE, bounds);
MutableTree leftRoot = treeDifference.getLeftTree();
String parentPath = rightTreeRef.getParentPath();
leftRoot.setChild(parentPath, newTreeNode);
}
}
use of org.locationtech.geogig.api.plumbing.diff.MutableTree in project GeoGig by boundlessgeo.
the class WriteTree2 method _call.
/**
* Executes the write tree operation.
*
* @return the new root tree id, the current HEAD tree id if there are no differences between
* the index and the HEAD, or {@code null} if the operation has been cancelled (as
* indicated by the {@link #getProgressListener() progress listener}.
*/
@Override
protected ObjectId _call() {
final ProgressListener progress = getProgressListener();
TreeDifference treeDifference = computeTreeDifference();
if (treeDifference.areEqual()) {
MutableTree leftTree = treeDifference.getLeftTree();
Node leftNode = leftTree.getNode();
ObjectId leftOid = leftNode.getObjectId();
return leftOid;
}
final MutableTree oldLeftTree = treeDifference.getLeftTree().clone();
Preconditions.checkState(oldLeftTree.equals(treeDifference.getLeftTree()));
// handle renames before new and deleted trees for the computation of new and deleted to be
// accurate
Set<String> ignoreList = Sets.newHashSet();
handleRenames(treeDifference, ignoreList);
handlePureMetadataChanges(treeDifference, ignoreList);
handleNewTrees(treeDifference, ignoreList);
handleDeletedTrees(treeDifference, ignoreList);
handleRemainingDifferences(treeDifference, ignoreList);
progress.complete();
MutableTree newLeftTree = treeDifference.getLeftTree();
final ObjectDatabase repositoryDatabase = objectDatabase();
final RevTree newRoot = newLeftTree.build(stagingDatabase(), repositoryDatabase);
if (newRoot.trees().isPresent()) {
for (Node n : newRoot.trees().get()) {
if (n.getMetadataId().isPresent())
deepMove(n.getMetadataId().get());
}
}
ObjectId newRootId = newRoot.getId();
return newRootId;
}
Aggregations