use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpTest method testPathFilterSingleFeature.
@Test
public void testPathFilterSingleFeature() throws Exception {
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
List<RevCommit> allCommits = Lists.newArrayList();
RevCommit expectedCommit = null;
for (Feature f : features) {
insertAndAdd(f);
String id = f.getIdentifier().getID();
final RevCommit commit = geogig.command(CommitOp.class).call();
if (id.equals(lines1.getIdentifier().getID())) {
expectedCommit = commit;
}
allCommits.add(commit);
}
String path = NodeRef.appendChild(linesName, lines1.getIdentifier().getID());
List<RevCommit> feature2_1Commits = toList(logOp.addPath(path).call());
assertEquals(1, feature2_1Commits.size());
assertEquals(Collections.singletonList(expectedCommit), feature2_1Commits);
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpTest method testTemporalConstraint.
@Test
public void testTemporalConstraint() throws Exception {
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
List<Long> timestamps = Arrays.asList(Long.valueOf(1000), Long.valueOf(2000), Long.valueOf(3000), Long.valueOf(4000), Long.valueOf(5000), Long.valueOf(6000));
LinkedList<RevCommit> allCommits = new LinkedList<RevCommit>();
for (int i = 0; i < features.size(); i++) {
Feature f = features.get(i);
Long timestamp = timestamps.get(i);
insertAndAdd(f);
final RevCommit commit = geogig.command(CommitOp.class).setCommitterTimestamp(timestamp).call();
allCommits.addFirst(commit);
}
// test time range exclusive
boolean minInclusive = false;
boolean maxInclusive = false;
Range<Date> commitRange = new Range<Date>(Date.class, new Date(2000), minInclusive, new Date(5000), maxInclusive);
logOp.setTimeRange(commitRange);
List<RevCommit> logged = toList(logOp.call());
List<RevCommit> expected = allCommits.subList(2, 4);
assertEquals(expected, logged);
// test time range inclusive
minInclusive = true;
maxInclusive = true;
commitRange = new Range<Date>(Date.class, new Date(2000), minInclusive, new Date(5000), maxInclusive);
logOp = geogig.command(LogOp.class).setTimeRange(commitRange);
logged = toList(logOp.call());
expected = allCommits.subList(1, 5);
assertEquals(expected, logged);
// test reset time range
logOp = geogig.command(LogOp.class).setTimeRange(commitRange).setTimeRange(null);
logged = toList(logOp.call());
expected = allCommits;
assertEquals(expected, logged);
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class OSMUpdateOp method _call.
/**
* Executes the {@code OSMUpdateOp} operation.
*
* @return a {@link OSMDownloadReport} of the operation
*/
@Override
protected Optional<OSMReport> _call() {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't update.");
Preconditions.checkState(currHead.get() instanceof SymRef, "Can't update from detached HEAD");
List<OSMLogEntry> entries = command(ReadOSMLogEntries.class).call();
checkArgument(!entries.isEmpty(), "Not in a geogig repository with OSM data");
Iterator<RevCommit> log = command(LogOp.class).setFirstParentOnly(false).setTopoOrder(false).call();
RevCommit lastCommit = null;
OSMLogEntry lastEntry = null;
while (log.hasNext()) {
RevCommit commit = log.next();
for (OSMLogEntry entry : entries) {
if (entry.getId().equals(commit.getTreeId())) {
lastCommit = commit;
lastEntry = entry;
break;
}
}
if (lastCommit != null) {
break;
}
}
checkNotNull(lastCommit, "The current branch does not contain OSM data");
command(BranchCreateOp.class).setSource(lastCommit.getId().toString()).setName(OSMUtils.OSM_FETCH_BRANCH).setAutoCheckout(true).setForce(true).call();
Optional<String> filter = command(ReadOSMFilterFile.class).setEntry(lastEntry).call();
Preconditions.checkState(filter.isPresent(), "Filter file not found");
message = message == null ? "Updated OSM data" : message;
Optional<OSMReport> report = command(OSMImportOp.class).setMessage(message).setFilter(filter.get()).setDataSource(apiUrl).setProgressListener(getProgressListener()).call();
if (!report.isPresent()) {
return report;
}
if (!getProgressListener().isCanceled()) {
command(CheckoutOp.class).setSource(((SymRef) currHead.get()).getTarget()).call();
Optional<Ref> upstreamRef = command(RefParse.class).setName(OSMUtils.OSM_FETCH_BRANCH).call();
Supplier<ObjectId> commitSupplier = Suppliers.ofInstance(upstreamRef.get().getObjectId());
if (rebase) {
getProgressListener().setDescription("Rebasing updated features...");
command(RebaseOp.class).setUpstream(commitSupplier).setProgressListener(getProgressListener()).call();
} else {
getProgressListener().setDescription("Merging updated features...");
command(MergeOp.class).addCommit(commitSupplier).setProgressListener(getProgressListener()).call();
}
}
return report;
}
use of org.locationtech.geogig.api.RevCommit 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.RevCommit in project GeoGig by boundlessgeo.
the class RebuildGraphOp method _call.
/**
* Executes the {@code RebuildGraphOp} operation.
*
* @return a list of {@link ObjectId}s that were found to be missing or incomplete
*/
@Override
protected ImmutableList<ObjectId> _call() {
Repository repository = repository();
Preconditions.checkState(!repository.isSparse(), "Cannot rebuild the graph of a sparse repository.");
List<ObjectId> updated = new LinkedList<ObjectId>();
ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true).call();
GraphDatabase graphDb = repository.graphDatabase();
for (Ref ref : branches) {
Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call();
while (commits.hasNext()) {
RevCommit next = commits.next();
if (graphDb.put(next.getId(), next.getParentIds())) {
updated.add(next.getId());
}
}
}
return ImmutableList.copyOf(updated);
}
Aggregations