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."));
}
}
}
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;
}
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;
}
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);
}
}
}
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;
}
}
}
Aggregations