Search in sources :

Example 1 with TransferSummary

use of org.locationtech.geogig.api.porcelain.TransferSummary in project GeoGig by boundlessgeo.

the class FetchWebOp method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    final Context geogig = this.getCommandLocator(context);
    FetchOp command = geogig.command(FetchOp.class);
    command.addRemote(remote);
    try {
        final TransferSummary result = command.setAll(fetchAll).setPrune(prune).call();
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeFetchResponse(result);
                out.finish();
            }
        });
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                context.setResponseContent(CommandResponse.error("Unable to fetch, the remote history is shallow."));
        }
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) FetchOp(org.locationtech.geogig.api.porcelain.FetchOp) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 2 with TransferSummary

use of org.locationtech.geogig.api.porcelain.TransferSummary in project GeoGig by boundlessgeo.

the class SendPack method callInternal.

private TransferSummary callInternal(IRemoteRepo remoteRepo) {
    final Remote remote = this.remote;
    @Nullable String localRefSpec;
    @Nullable String remoteRefSpec;
    boolean force;
    TransferSummary result = new TransferSummary();
    for (TransferableRef ref : this.refsToPush) {
        localRefSpec = ref.getLocalRef();
        remoteRefSpec = ref.getRemoteRef();
        force = ref.isForceUpdate();
        if (ref.isDelete()) {
            Optional<Ref> deleted = remoteRepo.deleteRef(remoteRefSpec);
            if (deleted.isPresent()) {
                ChangedRef deleteResult = new ChangedRef(deleted.get(), null, REMOVED_REF);
                result.add(remote.getPushURL(), deleteResult);
            }
        } else {
            Optional<Ref> localRef = refParse(localRefSpec);
            checkState(localRef.isPresent(), "RefSpec %s does not exist", localRefSpec);
            Optional<Ref> newRef = push(remoteRepo, remote, localRef.get(), remoteRefSpec);
            if (newRef.isPresent()) {
                ChangeTypes changeType = remoteRefSpec == null ? ADDED_REF : CHANGED_REF;
                ChangedRef deleteResult = new ChangedRef(localRef.get(), newRef.get(), changeType);
                result.add(remote.getPushURL(), deleteResult);
            }
        }
    }
    return result;
}
Also used : ChangedRef(org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef) Ref(org.locationtech.geogig.api.Ref) Remote(org.locationtech.geogig.api.Remote) ChangedRef(org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) ChangeTypes(org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef.ChangeTypes) Nullable(javax.annotation.Nullable)

Example 3 with TransferSummary

use of org.locationtech.geogig.api.porcelain.TransferSummary in project GeoGig by boundlessgeo.

the class SendPack method _call.

@Override
protected TransferSummary _call() {
    checkState(remote != null, "no remote specified");
    checkState(!refsToPush.isEmpty(), "no refs to push specified");
    final IRemoteRepo remoteRepo = openRemoteRepo(remote);
    TransferSummary transferResult;
    try {
        transferResult = callInternal(remoteRepo);
        checkState(transferResult != null);
    } finally {
        try {
            remoteRepo.close();
        } catch (IOException e) {
            Throwables.propagate(e);
        }
    }
    return transferResult;
}
Also used : IRemoteRepo(org.locationtech.geogig.remote.IRemoteRepo) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) IOException(java.io.IOException)

Example 4 with TransferSummary

use of org.locationtech.geogig.api.porcelain.TransferSummary 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 5 with TransferSummary

use of org.locationtech.geogig.api.porcelain.TransferSummary in project GeoGig by boundlessgeo.

the class Push method runInternal.

/**
     * Executes the push command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    PushOp push = cli.getGeogig().command(PushOp.class);
    push.setProgressListener(cli.getProgressListener());
    push.setAll(all);
    if (args != null) {
        if (args.size() > 0) {
            push.setRemote(args.get(0));
        }
        for (int i = 1; i < args.size(); i++) {
            push.addRefSpec(args.get(i));
        }
    }
    try {
        // TODO: listen on progress?
        TransferSummary dataPushed = push.call();
        if (dataPushed.isEmpty()) {
            cli.getConsole().println("Nothing to push.");
        }
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case REMOTE_HAS_CHANGES:
                throw new CommandFailedException("Push failed: The remote repository has changes that would be lost in the event of a push.", e);
            case HISTORY_TOO_SHALLOW:
                throw new CommandFailedException("Push failed: There is not enough local history to complete the push.", e);
            case CANNOT_PUSH_TO_SYMBOLIC_REF:
                throw new CommandFailedException("Push failed: Cannot push to a symbolic reference", e);
            default:
                break;
        }
    }
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Aggregations

TransferSummary (org.locationtech.geogig.api.porcelain.TransferSummary)7 SynchronizationException (org.locationtech.geogig.api.porcelain.SynchronizationException)5 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 ConsoleReader (jline.console.ConsoleReader)2 Context (org.locationtech.geogig.api.Context)2 Ref (org.locationtech.geogig.api.Ref)2 FetchOp (org.locationtech.geogig.api.porcelain.FetchOp)2 PushOp (org.locationtech.geogig.api.porcelain.PushOp)2 CommandContext (org.locationtech.geogig.web.api.CommandContext)2 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)2 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)2 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 Remote (org.locationtech.geogig.api.Remote)1 DiffObjectCount (org.locationtech.geogig.api.plumbing.diff.DiffObjectCount)1 PullOp (org.locationtech.geogig.api.porcelain.PullOp)1 PullResult (org.locationtech.geogig.api.porcelain.PullResult)1 ChangedRef (org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef)1 ChangeTypes (org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef.ChangeTypes)1