use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class LsTree method runInternal.
@Override
public void runInternal(final GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Strategy lsStrategy = Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = Strategy.TREES_ONLY;
}
}
Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
final ConsoleReader console = cli.getConsole();
Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {
@Override
public CharSequence apply(NodeRef input) {
StringBuilder sb = new StringBuilder();
if (!verbose) {
sb.append(input.path());
} else {
Envelope env = new Envelope();
input.getNode().expand(env);
StringBuilder sbenv = new StringBuilder();
sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
if (input.getType().equals(TYPE.TREE)) {
RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
}
}
return sb;
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class Conflicts method printConflictDiff.
private void printConflictDiff(Conflict conflict, ConsoleReader console, GeoGIG geogig) throws IOException {
FullDiffPrinter diffPrinter = new FullDiffPrinter(false, true);
console.println("---" + conflict.getPath() + "---");
ObjectId theirsHeadId;
Optional<Ref> mergeHead = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
if (mergeHead.isPresent()) {
theirsHeadId = mergeHead.get().getObjectId();
} else {
File branchFile = new File(getRebaseFolder(), "branch");
Preconditions.checkState(branchFile.exists(), "Cannot find merge/rebase head reference");
try {
String currentBranch = Files.readFirstLine(branchFile, Charsets.UTF_8);
Optional<Ref> rebaseHead = geogig.command(RefParse.class).setName(currentBranch).call();
theirsHeadId = rebaseHead.get().getObjectId();
} catch (IOException e) {
throw new IllegalStateException("Cannot read current branch info file");
}
}
Optional<RevCommit> theirsHead = geogig.command(RevObjectParse.class).setObjectId(theirsHeadId).call(RevCommit.class);
ObjectId oursHeadId = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call().get().getObjectId();
Optional<RevCommit> oursHead = geogig.command(RevObjectParse.class).setObjectId(oursHeadId).call(RevCommit.class);
Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class).setLeft(theirsHead.get()).setRight(oursHead.get()).call();
String ancestorPath = commonAncestor.get().toString() + ":" + conflict.getPath();
Optional<NodeRef> ancestorNodeRef = geogig.command(FeatureNodeRefFromRefspec.class).setRefspec(ancestorPath).call();
String path = Ref.ORIG_HEAD + ":" + conflict.getPath();
Optional<NodeRef> oursNodeRef = geogig.command(FeatureNodeRefFromRefspec.class).setRefspec(path).call();
DiffEntry diffEntry = new DiffEntry(ancestorNodeRef.orNull(), oursNodeRef.orNull());
console.println("Ours");
diffPrinter.print(geogig, console, diffEntry);
path = theirsHeadId + ":" + conflict.getPath();
Optional<NodeRef> theirsNodeRef = geogig.command(FeatureNodeRefFromRefspec.class).setRefspec(path).call();
diffEntry = new DiffEntry(ancestorNodeRef.orNull(), theirsNodeRef.orNull());
console.println("Theirs");
diffPrinter.print(geogig, console, diffEntry);
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class FullDiffPrinter method formatPath.
private static String formatPath(DiffEntry entry) {
String path;
NodeRef oldObject = entry.getOldObject();
NodeRef newObject = entry.getNewObject();
if (oldObject == null) {
path = newObject.path();
} else if (newObject == null) {
path = oldObject.path();
} else {
if (oldObject.path().equals(newObject.path())) {
path = oldObject.path();
} else {
path = oldObject.path() + " -> " + newObject.path();
}
}
return path;
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class RevertOp method applyRevertedChanges.
private List<Conflict> applyRevertedChanges(RevCommit commit) {
ObjectId parentCommitId = ObjectId.NULL;
if (commit.getParentIds().size() > 0) {
parentCommitId = commit.getParentIds().get(0);
}
ObjectId parentTreeId = ObjectId.NULL;
Repository repository = repository();
if (repository.commitExists(parentCommitId)) {
parentTreeId = repository.getCommit(parentCommitId).getTreeId();
}
// get changes (in reverse)
Iterator<DiffEntry> reverseDiff = command(DiffTree.class).setNewTree(parentTreeId).setOldTree(commit.getTreeId()).setReportTrees(false).call();
ObjectId headTreeId = repository.getCommit(revertHead).getTreeId();
final RevTree headTree = repository.getTree(headTreeId);
ArrayList<Conflict> conflicts = new ArrayList<Conflict>();
DiffEntry diff;
while (reverseDiff.hasNext()) {
diff = reverseDiff.next();
if (diff.isAdd()) {
// Feature was deleted
Optional<NodeRef> node = command(FindTreeChild.class).setChildPath(diff.newPath()).setIndex(true).setParent(headTree).call();
// make sure it is still deleted
if (node.isPresent()) {
conflicts.add(new Conflict(diff.newPath(), diff.oldObjectId(), node.get().objectId(), diff.newObjectId()));
} else {
index().stage(getProgressListener(), Iterators.singletonIterator(diff), 1);
}
} else {
// Feature was added or modified
Optional<NodeRef> node = command(FindTreeChild.class).setChildPath(diff.oldPath()).setIndex(true).setParent(headTree).call();
ObjectId nodeId = node.get().getNode().getObjectId();
// Make sure it wasn't changed
if (node.isPresent() && nodeId.equals(diff.oldObjectId())) {
index().stage(getProgressListener(), Iterators.singletonIterator(diff), 1);
} else {
// do not mark as conflict if reverting to the same feature currently in HEAD
if (!nodeId.equals(diff.newObjectId())) {
conflicts.add(new Conflict(diff.newPath(), diff.oldObjectId(), node.get().objectId(), diff.newObjectId()));
}
}
}
}
return conflicts;
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class CreatePatchOp method _call.
@Override
protected Patch _call() {
Patch patch = new Patch();
Map<ObjectId, RevFeatureType> featureTypes = Maps.newHashMap();
while (diffs.hasNext()) {
DiffEntry diffEntry = diffs.next();
final NodeRef newObject = diffEntry.getNewObject();
final NodeRef oldObject = diffEntry.getOldObject();
if (diffEntry.changeType() == ChangeType.MODIFIED) {
RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.newObjectId()).call().get();
if (revObject instanceof RevFeature) {
FeatureDiff diff = command(DiffFeature.class).setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject())).setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call();
patch.addModifiedFeature(diff);
} else if (revObject instanceof RevTree) {
RevFeatureType oldFeatureType = command(RevObjectParse.class).setObjectId(diffEntry.getOldObject().getMetadataId()).call(RevFeatureType.class).get();
RevFeatureType newFeatureType = command(RevObjectParse.class).setObjectId(diffEntry.getNewObject().getMetadataId()).call(RevFeatureType.class).get();
patch.addFeatureType(oldFeatureType);
patch.addFeatureType(newFeatureType);
patch.addAlteredTree(diffEntry);
}
} else if (diffEntry.changeType() == ChangeType.ADDED) {
RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.newObjectId()).call().get();
if (revObject instanceof RevFeature) {
RevFeatureType featureType;
if (featureTypes.containsKey(newObject.getMetadataId())) {
featureType = featureTypes.get(newObject.getMetadataId());
} else {
featureType = command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call(RevFeatureType.class).get();
featureTypes.put(newObject.getMetadataId(), featureType);
}
FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
Feature feature = featureBuilder.build(diffEntry.newObjectId().toString(), (RevFeature) revObject);
String name = diffEntry.newPath();
patch.addAddedFeature(name, feature, featureType);
} else if (revObject instanceof RevTree) {
ObjectId metadataId = diffEntry.getNewObject().getMetadataId();
if (!metadataId.isNull()) {
RevFeatureType featureType = command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class).get();
patch.addAlteredTree(diffEntry);
patch.addFeatureType(featureType);
}
}
} else if (diffEntry.changeType() == ChangeType.REMOVED) {
RevObject revObject = command(RevObjectParse.class).setObjectId(diffEntry.oldObjectId()).call().get();
if (revObject instanceof RevFeature) {
RevFeatureType featureType;
if (featureTypes.containsKey(oldObject.getMetadataId())) {
featureType = featureTypes.get(oldObject.getMetadataId());
} else {
featureType = command(RevObjectParse.class).setObjectId(oldObject.getMetadataId()).call(RevFeatureType.class).get();
featureTypes.put(oldObject.getMetadataId(), featureType);
}
FeatureBuilder featureBuilder = new FeatureBuilder(featureType);
Feature feature = featureBuilder.build(diffEntry.oldObjectId().toString(), (RevFeature) revObject);
String name = diffEntry.oldPath();
patch.addRemovedFeature(name, feature, featureType);
} else if (revObject instanceof RevTree) {
ObjectId metadataId = diffEntry.getOldObject().getMetadataId();
if (!metadataId.isNull()) {
RevFeatureType featureType = command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class).get();
patch.addAlteredTree(diffEntry);
patch.addFeatureType(featureType);
}
}
}
}
return patch;
}
Aggregations