use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class LsTreeOp method _call.
/**
* @see java.util.concurrent.Callable#call()
*/
protected Iterator<NodeRef> _call() {
String ref = this.ref;
if (ref == null) {
ref = Ref.WORK_HEAD;
}
ObjectId metadataId = ObjectId.NULL;
final String path = ref.lastIndexOf(':') != -1 ? ref.substring(ref.lastIndexOf(':') + 1) : "";
if (!path.isEmpty()) {
final String providedRefName = ref.lastIndexOf(':') != -1 ? ref.substring(0, ref.lastIndexOf(':')) : null;
if (providedRefName != null) {
Optional<ObjectId> rootTreeId = command(ResolveTreeish.class).setTreeish(providedRefName).call();
if (rootTreeId.isPresent()) {
RevTree rootTree = command(RevObjectParse.class).setObjectId(rootTreeId.get()).call(RevTree.class).get();
Optional<NodeRef> treeRef = command(FindTreeChild.class).setChildPath(path).setIndex(true).setParent(rootTree).call();
metadataId = treeRef.isPresent() ? treeRef.get().getMetadataId() : ObjectId.NULL;
}
}
}
// is it just a ref name?
Optional<Ref> reference = command(RefParse.class).setName(ref).call();
if (reference.isPresent()) {
if (reference.get().getObjectId().isNull()) {
return Iterators.emptyIterator();
}
}
Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
Optional<NodeRef> treeRef = Optional.absent();
if (!revObject.isPresent()) {
if (Ref.WORK_HEAD.equals(ref)) {
// tree but it is empty
return Iterators.emptyIterator();
}
// let's try to see if it is a feature type or feature in the working tree
NodeRef.checkValidPath(ref);
treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
Preconditions.checkArgument(treeRef.isPresent(), "Invalid reference: %s", ref);
ObjectId treeId = treeRef.get().objectId();
metadataId = treeRef.get().getMetadataId();
revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
}
checkArgument(revObject.isPresent(), "Invalid reference: %s", ref);
final TYPE type = revObject.get().getType();
switch(type) {
case FEATURE:
NodeRef nodeRef = treeRef.isPresent() ? treeRef.get() : null;
List<NodeRef> nodeRefs = Lists.newArrayList();
nodeRefs.add(nodeRef);
// If show trees options is passed in show all trees that contain this feature
if (this.strategy == Strategy.TREES_ONLY) {
if (nodeRef != null) {
while (!nodeRef.getParentPath().isEmpty()) {
treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(nodeRef.getParentPath()).setIndex(true).call();
nodeRef = treeRef.get();
nodeRefs.add(nodeRef);
}
}
}
return nodeRefs.iterator();
case COMMIT:
RevCommit revCommit = (RevCommit) revObject.get();
ObjectId treeId = revCommit.getTreeId();
revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
case TREE:
DepthTreeIterator.Strategy iterStrategy;
switch(this.strategy) {
case CHILDREN:
iterStrategy = DepthTreeIterator.Strategy.CHILDREN;
break;
case FEATURES_ONLY:
iterStrategy = DepthTreeIterator.Strategy.FEATURES_ONLY;
break;
case TREES_ONLY:
iterStrategy = DepthTreeIterator.Strategy.TREES_ONLY;
break;
case DEPTHFIRST:
iterStrategy = DepthTreeIterator.Strategy.RECURSIVE;
break;
case DEPTHFIRST_ONLY_FEATURES:
iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_FEATURES_ONLY;
break;
case DEPTHFIRST_ONLY_TREES:
iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_TREES_ONLY;
break;
default:
throw new IllegalStateException("Unknown strategy: " + this.strategy);
}
RevTree tree = (RevTree) revObject.get();
ObjectDatabase database = stagingDatabase();
DepthTreeIterator iter = new DepthTreeIterator(path, metadataId, tree, database, iterStrategy);
iter.setBoundsFilter(refBoundsFilter);
return iter;
default:
throw new IllegalArgumentException(String.format("Invalid reference: %s", ref));
}
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class RevParse method resolveCommit.
/**
* @param objectId
* @return
*/
private RevCommit resolveCommit(ObjectId objectId) {
final Optional<RevObject> object = command(RevObjectParse.class).setObjectId(objectId).call();
checkArgument(object.isPresent(), "No object named %s could be found", objectId);
final RevObject revObject = object.get();
RevCommit commit;
switch(revObject.getType()) {
case COMMIT:
commit = (RevCommit) revObject;
break;
case TAG:
ObjectId commitId = ((RevTag) revObject).getCommitId();
commit = command(RevObjectParse.class).setObjectId(commitId).call(RevCommit.class).get();
break;
default:
throw new IllegalArgumentException(String.format("%s did not resolve to a commit or tag: %s", objectId, revObject.getType()));
}
return commit;
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class CherryPickOpTest method testCherryPickWithConflicts.
@Test
public void testCherryPickWithConflicts() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
// create branch1, checkout and add a commit
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insert(points2);
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource(Ref.MASTER).call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).call();
try {
geogig.command(CherryPickOp.class).setCommit(Suppliers.ofInstance(branchCommit.getId())).call();
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("conflict in Points/Points.1"));
}
Optional<Ref> cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
assertTrue(cherrypickHead.isPresent());
// check that unconflicted changes are in index and working tree
Optional<RevObject> pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points2), pts2.get());
pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points2), pts2.get());
// solve and commit
Feature points1Solved = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Solved);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setCommit(branchCommit).call();
Optional<RevObject> ptsSolved = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP1)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points1Solved), ptsSolved.get());
cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
assertFalse(cherrypickHead.isPresent());
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class CloneOpTest method testClone.
@Test
public void testClone() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got all of the commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class CloneOpTest method testShallowClone.
@Test
public void testShallowClone() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(2);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got only 2 commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(2, logged.size());
assertEquals(expected.get(0), logged.get(0));
assertEquals(expected.get(1), logged.get(1));
}
Aggregations