Search in sources :

Example 1 with DiffObjectCount

use of org.locationtech.geogig.api.plumbing.diff.DiffObjectCount in project GeoGig by boundlessgeo.

the class Add method runInternal.

/**
     * Executes the add command using the provided options.
     * 
     * @param cli
     * @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    final ConsoleReader console = cli.getConsole();
    String pathFilter = null;
    if (patterns.size() == 1) {
        pathFilter = patterns.get(0);
    } else if (patterns.size() > 1) {
        throw new InvalidParameterException("Only a single path is supported so far");
    }
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    console.print("Counting unstaged elements...");
    console.flush();
    DiffObjectCount unstaged = geogig.getRepository().workingTree().countUnstaged(pathFilter);
    if (0 == unstaged.count() && conflicts.isEmpty()) {
        console.println();
        console.println("No unstaged elements, exiting.");
        return;
    } else {
        console.println(String.valueOf(unstaged.count()));
    }
    console.println("Staging changes...");
    AddOp op = geogig.command(AddOp.class);
    if (patterns.size() == 1) {
        op.addPattern(patterns.get(0));
    }
    WorkingTree workTree = op.setUpdateOnly(updateOnly).setProgressListener(cli.getProgressListener()).call();
    DiffObjectCount staged = geogig.getRepository().index().countStaged(null);
    unstaged = workTree.countUnstaged(null);
    console.println(staged.featureCount() + " features and " + staged.treeCount() + " trees staged for commit");
    console.println(unstaged.featureCount() + " features and " + unstaged.treeCount() + " trees not staged for commit");
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) ConsoleReader(jline.console.ConsoleReader) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 2 with DiffObjectCount

use of org.locationtech.geogig.api.plumbing.diff.DiffObjectCount in project GeoGig by boundlessgeo.

the class Pull method runInternal.

/**
     * Executes the pull command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(depth > 0 ? !fulldepth : true, "Cannot specify a depth and full depth.  Use --depth <depth> or --fulldepth.");
    GeoGIG geogig = cli.getGeogig();
    if (depth > 0 || fulldepth) {
        if (!geogig.getRepository().getDepth().isPresent()) {
            throw new CommandFailedException("Depth operations can only be used on a shallow clone.");
        }
    }
    PullOp pull = geogig.command(PullOp.class);
    pull.setProgressListener(cli.getProgressListener());
    pull.setAll(all).setRebase(rebase).setFullDepth(fulldepth);
    pull.setDepth(depth);
    if (args != null) {
        if (args.size() > 0) {
            pull.setRemote(args.get(0));
        }
        for (int i = 1; i < args.size(); i++) {
            pull.addRefSpec(args.get(i));
        }
    }
    try {
        final PullResult result = pull.call();
        ConsoleReader console = cli.getConsole();
        TransferSummary fetchResult = result.getFetchResult();
        FetchResultPrinter.print(fetchResult, console);
        final Ref oldRef = result.getOldRef();
        final Ref newRef = result.getNewRef();
        if (oldRef == null && newRef == null) {
            console.println("Nothing to pull.");
        } else if (Objects.equal(oldRef, newRef)) {
            String name = oldRef == null ? newRef.getName() : oldRef.getName();
            name = Ref.localName(name);
            console.println(name + " already up to date.");
        } else {
            String oldTreeish;
            String newTreeish = newRef.getObjectId().toString();
            if (oldRef == null) {
                console.println("From " + result.getRemoteName());
                console.println(" * [new branch]     " + newRef.localName() + " -> " + newRef.getName());
                oldTreeish = ObjectId.NULL.toString();
            } else {
                oldTreeish = oldRef.getObjectId().toString();
            }
            DiffObjectCount count = geogig.command(DiffCount.class).setOldVersion(oldTreeish).setNewVersion(newTreeish).call();
            long added = count.getFeaturesAdded();
            long removed = count.getFeaturesRemoved();
            long modified = count.getFeaturesChanged();
            console.println(String.format("Features Added: %,d Removed: %,d Modified: %,d", added, removed, modified));
        }
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                throw new CommandFailedException("Unable to pull, the remote history is shallow.", e);
        }
    }
}
Also used : PullOp(org.locationtech.geogig.api.porcelain.PullOp) Ref(org.locationtech.geogig.api.Ref) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) ConsoleReader(jline.console.ConsoleReader) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) PullResult(org.locationtech.geogig.api.porcelain.PullResult) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 3 with DiffObjectCount

use of org.locationtech.geogig.api.plumbing.diff.DiffObjectCount 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);
    }
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ObjectId(org.locationtech.geogig.api.ObjectId) Change(org.locationtech.geogig.osm.internal.history.Change) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) Iterator(java.util.Iterator) Changeset(org.locationtech.geogig.osm.internal.history.Changeset) DiffCount(org.locationtech.geogig.api.plumbing.DiffCount) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 4 with DiffObjectCount

use of org.locationtech.geogig.api.plumbing.diff.DiffObjectCount 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);
    }
}
Also used : DiffBounds(org.locationtech.geogig.api.plumbing.DiffBounds) ConsoleReader(jline.console.ConsoleReader) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DiffCount(org.locationtech.geogig.api.plumbing.DiffCount) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 5 with DiffObjectCount

use of org.locationtech.geogig.api.plumbing.diff.DiffObjectCount in project GeoGig by boundlessgeo.

the class DiffCount method _call.

@Override
protected DiffObjectCount _call() {
    checkState(oldRefSpec != null, "old ref spec not provided");
    checkState(newRefSpec != null, "new ref spec not provided");
    final RevTree oldTree = getTree(oldRefSpec);
    final RevTree newTree = getTree(newRefSpec);
    DiffObjectCount diffCount;
    StagingDatabase index = stagingDatabase();
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(oldTree, newTree, index, index);
    DiffCountConsumer counter = new DiffCountConsumer(index);
    PreOrderDiffWalk.Consumer filter = counter;
    if (!pathFilters.isEmpty()) {
        filter = new PathFilteringDiffConsumer(pathFilters, counter);
    }
    visitor.walk(filter);
    diffCount = counter.get();
    return diffCount;
}
Also used : DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) DiffCountConsumer(org.locationtech.geogig.api.plumbing.diff.DiffCountConsumer) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)

Aggregations

DiffObjectCount (org.locationtech.geogig.api.plumbing.diff.DiffObjectCount)5 GeoGIG (org.locationtech.geogig.api.GeoGIG)4 ConsoleReader (jline.console.ConsoleReader)3 DiffCount (org.locationtech.geogig.api.plumbing.DiffCount)2 AddOp (org.locationtech.geogig.api.porcelain.AddOp)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 WorkingTree (org.locationtech.geogig.repository.WorkingTree)2 Iterator (java.util.Iterator)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 Ref (org.locationtech.geogig.api.Ref)1 RevTree (org.locationtech.geogig.api.RevTree)1 DiffBounds (org.locationtech.geogig.api.plumbing.DiffBounds)1 DiffCountConsumer (org.locationtech.geogig.api.plumbing.diff.DiffCountConsumer)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 PathFilteringDiffConsumer (org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)1 PreOrderDiffWalk (org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk)1 Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)1 ConflictsReadOp (org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp)1 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)1 PullOp (org.locationtech.geogig.api.porcelain.PullOp)1