use of org.locationtech.geogig.api.porcelain.LogOp 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.porcelain.LogOp 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);
}
use of org.locationtech.geogig.api.porcelain.LogOp in project GeoGig by boundlessgeo.
the class LogOpTest method testAll.
@Test
public void testAll() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - branch1 - Points 2 added
// |
// o - Points 3 added
// |
// o - master - HEAD - Lines 1 added
insertAndAdd(points1);
final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// create branch1 and checkout
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
// checkout master
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(points3);
final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
insertAndAdd(lines1);
final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
LogOp op = geogig.command(LogOp.class);
op.addCommit(c2.getId());
op.addCommit(c4.getId());
Iterator<RevCommit> iterator = op.call();
assertNotNull(iterator);
assertTrue(iterator.hasNext());
assertEquals(c4, iterator.next());
assertTrue(iterator.hasNext());
assertEquals(c3, iterator.next());
assertTrue(iterator.hasNext());
assertEquals(c2, iterator.next());
assertTrue(iterator.hasNext());
assertEquals(c1, iterator.next());
assertFalse(iterator.hasNext());
}
use of org.locationtech.geogig.api.porcelain.LogOp in project GeoGig by boundlessgeo.
the class LogOpTest method testTemporalConstraint.
@Test
public void testTemporalConstraint() throws Exception {
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
List<Long> timestamps = Arrays.asList(Long.valueOf(1000), Long.valueOf(2000), Long.valueOf(3000), Long.valueOf(4000), Long.valueOf(5000), Long.valueOf(6000));
LinkedList<RevCommit> allCommits = new LinkedList<RevCommit>();
for (int i = 0; i < features.size(); i++) {
Feature f = features.get(i);
Long timestamp = timestamps.get(i);
insertAndAdd(f);
final RevCommit commit = geogig.command(CommitOp.class).setCommitterTimestamp(timestamp).call();
allCommits.addFirst(commit);
}
// test time range exclusive
boolean minInclusive = false;
boolean maxInclusive = false;
Range<Date> commitRange = new Range<Date>(Date.class, new Date(2000), minInclusive, new Date(5000), maxInclusive);
logOp.setTimeRange(commitRange);
List<RevCommit> logged = toList(logOp.call());
List<RevCommit> expected = allCommits.subList(2, 4);
assertEquals(expected, logged);
// test time range inclusive
minInclusive = true;
maxInclusive = true;
commitRange = new Range<Date>(Date.class, new Date(2000), minInclusive, new Date(5000), maxInclusive);
logOp = geogig.command(LogOp.class).setTimeRange(commitRange);
logged = toList(logOp.call());
expected = allCommits.subList(1, 5);
assertEquals(expected, logged);
// test reset time range
logOp = geogig.command(LogOp.class).setTimeRange(commitRange).setTimeRange(null);
logged = toList(logOp.call());
expected = allCommits;
assertEquals(expected, logged);
}
use of org.locationtech.geogig.api.porcelain.LogOp in project GeoGig by boundlessgeo.
the class StatisticsWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
final Context geogig = this.getCommandLocator(context);
final List<FeatureTypeStats> stats = Lists.newArrayList();
LogOp logOp = geogig.command(LogOp.class).setFirstParentOnly(true);
final Iterator<RevCommit> log;
if (since != null && !since.trim().isEmpty()) {
Date untilTime = new Date();
Date sinceTime = new Date(geogig.command(ParseTimestamp.class).setString(since).call());
logOp.setTimeRange(new Range<Date>(Date.class, sinceTime, untilTime));
}
if (this.until != null) {
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(this.until).call();
Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", this.until);
logOp.setUntil(until.get());
}
LsTreeOp lsTreeOp = geogig.command(LsTreeOp.class).setStrategy(LsTreeOp.Strategy.TREES_ONLY);
if (path != null && !path.trim().isEmpty()) {
lsTreeOp.setReference(path);
logOp.addPath(path);
}
final Iterator<NodeRef> treeIter = lsTreeOp.call();
while (treeIter.hasNext()) {
NodeRef node = treeIter.next();
stats.add(new FeatureTypeStats(node.path(), context.getGeoGIG().getRepository().getTree(node.objectId()).size()));
}
log = logOp.call();
RevCommit firstCommit = null;
RevCommit lastCommit = null;
int totalCommits = 0;
final List<RevPerson> authors = Lists.newArrayList();
if (log.hasNext()) {
lastCommit = log.next();
authors.add(lastCommit.getAuthor());
totalCommits++;
}
while (log.hasNext()) {
firstCommit = log.next();
RevPerson newAuthor = firstCommit.getAuthor();
// If the author isn't defined, use the committer for the purposes of statistics.
if (!newAuthor.getName().isPresent() && !newAuthor.getEmail().isPresent()) {
newAuthor = firstCommit.getCommitter();
}
if (newAuthor.getName().isPresent() || newAuthor.getEmail().isPresent()) {
boolean authorFound = false;
for (RevPerson author : authors) {
if (newAuthor.getName().equals(author.getName()) && newAuthor.getEmail().equals(author.getEmail())) {
authorFound = true;
break;
}
}
if (!authorFound) {
authors.add(newAuthor);
}
}
totalCommits++;
}
int addedFeatures = 0;
int modifiedFeatures = 0;
int removedFeatures = 0;
if (since != null && !since.trim().isEmpty() && firstCommit != null && lastCommit != null) {
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(firstCommit.getId()).setNewVersion(lastCommit.getId()).setFilter(path).call();
while (diff.hasNext()) {
DiffEntry entry = diff.next();
if (entry.changeType() == DiffEntry.ChangeType.ADDED) {
addedFeatures++;
} else if (entry.changeType() == DiffEntry.ChangeType.MODIFIED) {
modifiedFeatures++;
} else {
removedFeatures++;
}
}
}
final RevCommit first = firstCommit;
final RevCommit last = lastCommit;
final int total = totalCommits;
final int added = addedFeatures;
final int modified = modifiedFeatures;
final int removed = removedFeatures;
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start(true);
out.writeStatistics(stats, first, last, total, authors, added, modified, removed);
out.finish();
}
});
}
Aggregations