use of org.locationtech.geogig.api.plumbing.DiffCount in project GeoGig by boundlessgeo.
the class OSMHistoryImport method importOsmHistory.
private void importOsmHistory(GeogigCLI cli, ConsoleReader console, HistoryDownloader downloader, @Nullable Envelope featureFilter) throws IOException {
Iterator<Changeset> changesets = downloader.fetchChangesets();
GeoGIG geogig = cli.getGeogig();
WorkingTree workingTree = geogig.getContext().workingTree();
while (changesets.hasNext()) {
Changeset changeset = changesets.next();
if (changeset.isOpen()) {
throw new CommandFailedException("Can't import past changeset " + changeset.getId() + " as it is still open.");
}
String desc = String.format("obtaining osm changeset %,d...", changeset.getId());
console.print(desc);
console.flush();
Optional<Iterator<Change>> opchanges = changeset.getChanges().get();
if (!opchanges.isPresent()) {
updateBranchChangeset(geogig, changeset.getId());
console.println(" does not apply.");
console.flush();
continue;
}
Iterator<Change> changes = opchanges.get();
console.print("applying...");
console.flush();
ObjectId workTreeId = workingTree.getTree().getId();
long changeCount = insertChanges(cli, changes, featureFilter);
console.print(String.format("Applied %,d changes, staging...", changeCount));
console.flush();
ObjectId afterTreeId = workingTree.getTree().getId();
DiffObjectCount diffCount = geogig.command(DiffCount.class).setOldVersion(workTreeId.toString()).setNewVersion(afterTreeId.toString()).call();
geogig.command(AddOp.class).call();
console.println(String.format("done. %,d changes actually applied.", diffCount.featureCount()));
console.flush();
commit(cli, changeset);
}
}
use of org.locationtech.geogig.api.plumbing.DiffCount in project GeoGig by boundlessgeo.
the class Diff method runInternal.
/**
* Executes the diff command with the specified options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec);
checkParameter(!(nogeom && summary), "Only one printing mode allowed");
checkParameter(!(bounds && count), "Only one of --bounds or --count is allowed");
checkParameter(!(cached && refSpec.size() > 1), "--cached allows zero or one ref specs to compare the index with.");
GeoGIG geogig = cli.getGeogig();
String oldVersion = resolveOldVersion();
String newVersion = resolveNewVersion();
List<String> paths = removeEmptyPaths();
if (bounds) {
DiffBounds diff = geogig.command(DiffBounds.class).setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
diff.setPathFilters(paths);
CoordinateReferenceSystem crs = parseCrs();
if (crs != null) {
diff.setCRS(crs);
}
DiffSummary<BoundingBox, BoundingBox> diffBounds = diff.call();
BoundsDiffPrinter.print(geogig, cli.getConsole(), diffBounds);
return;
}
if (count) {
if (oldVersion == null) {
oldVersion = Ref.HEAD;
}
if (newVersion == null) {
newVersion = cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD;
}
DiffCount cdiff = geogig.command(DiffCount.class).setOldVersion(oldVersion).setNewVersion(newVersion);
cdiff.setFilter(paths);
DiffObjectCount count = cdiff.call();
ConsoleReader console = cli.getConsole();
console.println(String.format("Trees changed: %d, features changed: %,d", count.treeCount(), count.featureCount()));
console.flush();
return;
}
DiffOp diff = geogig.command(DiffOp.class);
diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached);
Iterator<DiffEntry> entries;
if (paths.isEmpty()) {
entries = diff.setProgressListener(cli.getProgressListener()).call();
} else {
entries = Iterators.emptyIterator();
for (String path : paths) {
Iterator<DiffEntry> moreEntries = diff.setFilter(path).setProgressListener(cli.getProgressListener()).call();
entries = Iterators.concat(entries, moreEntries);
}
}
if (!entries.hasNext()) {
cli.getConsole().println("No differences found");
return;
}
DiffPrinter printer;
if (summary) {
printer = new SummaryDiffPrinter();
} else {
printer = new FullDiffPrinter(nogeom, false);
}
DiffEntry entry;
while (entries.hasNext()) {
entry = entries.next();
printer.print(geogig, cli.getConsole(), entry);
}
}
Aggregations