use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class MergeBase method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(commits.size() == 2, "Two commit references must be provided");
ConsoleReader console = cli.getConsole();
GeoGIG geogig = cli.getGeogig();
Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)).call();
checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object.");
checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit");
Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)).call();
checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object.");
checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit");
Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class).setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call();
checkParameter(ancestor.isPresent(), "No common ancestor was found.");
console.print(ancestor.get().toString());
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class RevList method runInternal.
/**
* Executes the revlist command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(!args.commits.isEmpty(), "No starting commit provided");
geogig = cli.getGeogig();
LogOp op = geogig.command(LogOp.class).setTopoOrder(args.topo).setFirstParentOnly(args.firstParent);
for (String commit : args.commits) {
if (commit.contains("..")) {
checkParameter(args.commits.size() == 1, "Only one value accepted when using <since>..<until> syntax");
List<String> sinceUntil = ImmutableList.copyOf((Splitter.on("..").split(commit)));
checkParameter(sinceUntil.size() == 2 || sinceUntil.size() == 1, "Invalid refSpec format, expected [<commit> ...]|[<since>..<until>]: %s", commit);
String sinceRefSpec;
String untilRefSpec;
if (sinceUntil.size() == 1) {
// just until was given
sinceRefSpec = null;
untilRefSpec = sinceUntil.get(0);
} else {
sinceRefSpec = sinceUntil.get(0);
untilRefSpec = sinceUntil.get(1);
}
if (sinceRefSpec != null) {
Optional<ObjectId> since;
since = geogig.command(RevParse.class).setRefSpec(sinceRefSpec).call();
checkParameter(since.isPresent(), "Object not found '%s'", sinceRefSpec);
op.setSince(since.get());
}
if (untilRefSpec != null) {
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(untilRefSpec).call();
checkParameter(until.isPresent(), "Object not found '%s'", sinceRefSpec);
op.setUntil(until.get());
}
} else {
Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit).call();
checkParameter(commitId.isPresent(), "Object not found '%s'", commit);
checkParameter(geogig.getRepository().commitExists(commitId.get()), "%s does not resolve to a commit", commit);
op.addCommit(commitId.get());
}
}
if (args.author != null && !args.author.isEmpty()) {
op.setAuthor(args.author);
}
if (args.committer != null && !args.committer.isEmpty()) {
op.setCommiter(args.committer);
}
if (args.skip != null) {
op.setSkip(args.skip.intValue());
}
if (args.limit != null) {
op.setLimit(args.limit.intValue());
}
if (args.since != null || args.until != null) {
Date since = new Date(0);
Date until = new Date();
if (args.since != null) {
since = new Date(geogig.command(ParseTimestamp.class).setString(args.since).call());
}
if (args.until != null) {
until = new Date(geogig.command(ParseTimestamp.class).setString(args.until).call());
}
op.setTimeRange(new Range<Date>(Date.class, since, until));
}
if (!args.pathNames.isEmpty()) {
for (String s : args.pathNames) {
op.addPath(s);
}
}
Iterator<RevCommit> log = op.call();
console = cli.getConsole();
RawPrinter printer = new RawPrinter(args.changed);
while (log.hasNext()) {
printer.print(log.next());
console.flush();
}
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LocalRemoteRepo method pushNewData.
/**
* Push all new objects from the specified {@link Ref} to the given refspec.
*
* @param ref the local ref that points to new commit data
* @param refspec the refspec to push to
*/
@Override
public void pushNewData(final Ref ref, final String refspec, final ProgressListener progress) throws SynchronizationException {
Optional<Ref> remoteRef = remoteGeoGig.command(RefParse.class).setName(refspec).call();
remoteRef = remoteRef.or(remoteGeoGig.command(RefParse.class).setName(Ref.TAGS_PREFIX + refspec).call());
checkPush(ref, remoteRef);
CommitTraverser traverser = getPushTraverser(remoteRef);
traverser.traverse(ref.getObjectId());
progress.setDescription("Uploading objects to " + refspec);
progress.setProgress(0);
while (!traverser.commits.isEmpty()) {
ObjectId commitId = traverser.commits.pop();
walkHead(commitId, false, progress);
}
String nameToSet = remoteRef.isPresent() ? remoteRef.get().getName() : Ref.HEADS_PREFIX + refspec;
Ref updatedRef = remoteGeoGig.command(UpdateRef.class).setName(nameToSet).setNewValue(ref.getObjectId()).call().get();
Ref remoteHead = headRef();
if (remoteHead instanceof SymRef) {
if (((SymRef) remoteHead).getTarget().equals(updatedRef.getName())) {
remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(ref.getName()).call();
RevCommit commit = remoteGeoGig.getRepository().getCommit(ref.getObjectId());
remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
}
}
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LocalMappedRemoteRepo method updateRemoteRef.
/**
* Updates the remote ref that matches the given refspec.
*
* @param refspec the ref to update
* @param commitId the new value of the ref
* @param delete if true, the remote ref will be deleted
* @return the updated ref
*/
@Override
protected Optional<Ref> updateRemoteRef(String refspec, ObjectId commitId, boolean delete) {
Optional<Ref> updatedRef = remoteGeoGig.command(UpdateRef.class).setName(refspec).setNewValue(commitId).setDelete(delete).call();
if (updatedRef.isPresent()) {
final Ref remoteHead = headRef();
if (remoteHead instanceof SymRef) {
if (((SymRef) remoteHead).getTarget().equals(updatedRef.get().getName())) {
remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(updatedRef.get().getName()).call();
RevCommit commit = remoteGeoGig.getRepository().getCommit(commitId);
remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
}
}
}
return updatedRef;
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpTest method testSinceUntil.
@Test
public void testSinceUntil() throws Exception {
final ObjectId oid1_1 = insertAndAdd(points1);
final RevCommit commit1_1 = geogig.command(CommitOp.class).call();
insertAndAdd(points2);
final RevCommit commit1_2 = geogig.command(CommitOp.class).call();
insertAndAdd(lines1);
final RevCommit commit2_1 = geogig.command(CommitOp.class).call();
final ObjectId oid2_2 = insertAndAdd(lines2);
final RevCommit commit2_2 = geogig.command(CommitOp.class).call();
try {
logOp = geogig.command(LogOp.class);
logOp.setSince(oid1_1).call();
fail("Expected ISE as since is not a commit");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("since"));
}
try {
logOp = geogig.command(LogOp.class);
logOp.setSince(null).setUntil(oid2_2).call();
fail("Expected ISE as until is not a commit");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("until"));
}
List<RevCommit> logs;
List<RevCommit> expected;
logOp = geogig.command(LogOp.class);
logs = toList(logOp.setSince(commit1_2.getId()).setUntil(null).call());
expected = Arrays.asList(commit2_2, commit2_1);
assertEquals(expected, logs);
logOp = geogig.command(LogOp.class);
logs = toList(logOp.setSince(commit2_2.getId()).setUntil(null).call());
expected = Collections.emptyList();
assertEquals(expected, logs);
logOp = geogig.command(LogOp.class);
logs = toList(logOp.setSince(commit1_2.getId()).setUntil(commit2_1.getId()).call());
expected = Arrays.asList(commit2_1);
assertEquals(expected, logs);
logOp = geogig.command(LogOp.class);
logs = toList(logOp.setSince(null).setUntil(commit2_1.getId()).call());
expected = Arrays.asList(commit2_1, commit1_2, commit1_1);
assertEquals(expected, logs);
}
Aggregations