use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpPerformanceTest method createBranches.
private List<ObjectId> createBranches(int numBranches, int numCommits) {
List<ObjectId> list = Lists.newArrayList();
for (int i = 1; i <= numBranches; i++) {
String branchName = "branch" + Integer.toString(i);
geogig.command(CommitOp.class).setAllowEmpty(true).setMessage("Commit before " + branchName).call();
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName(branchName).call();
createCommits(numCommits / 2, branchName);
geogig.command(CheckoutOp.class).setSource(Ref.MASTER).call();
geogig.command(CommitOp.class).setAllowEmpty(true).setMessage("Commit during " + branchName).call();
geogig.command(CheckoutOp.class).setSource(branchName).call();
RevCommit lastCommit = createCommits(numCommits / 2, branchName);
geogig.command(CheckoutOp.class).setSource(Ref.MASTER).call();
list.add(lastCommit.getId());
// System.err.println("branch " + Integer.toString(i));
}
return list;
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpPerformanceTest method createAndLogMultipleCommits.
private void createAndLogMultipleCommits(int numCommits) throws Exception {
super.doSetUp();
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
System.err.println("***********\nCreating " + numberFormat.format(numCommits) + " commits...");
Stopwatch sw = Stopwatch.createStarted();
createCommits(numCommits, "");
sw.stop();
System.err.println(numberFormat.format(numCommits) + " created in " + sw.toString());
System.err.flush();
sw.reset().start();
Iterator<RevCommit> commits = geogig.command(LogOp.class).call();
sw.stop();
System.err.println("LogOp took " + sw.toString());
benchmarkIteration(commits);
super.tearDown();
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpPerformanceTest method createAndLogMultipleBranches.
private void createAndLogMultipleBranches(int numBranches, int numCommits) throws Exception {
super.doSetUp();
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
System.err.println("***********\nCreating " + numberFormat.format(numBranches) + " branches with " + numberFormat.format(numCommits) + " commits each...");
Stopwatch sw = Stopwatch.createStarted();
List<ObjectId> ids = createBranches(numBranches, numCommits);
sw.stop();
System.err.println(numberFormat.format(numBranches) + " branches with " + numberFormat.format(numCommits) + " comits each created in " + sw.toString());
System.err.flush();
LogOp op = geogig.command(LogOp.class);
for (ObjectId id : ids) {
op.addCommit(id);
}
sw.reset().start();
Iterator<RevCommit> commits = op.call();
sw.stop();
System.err.println("LogOp took " + sw.toString());
benchmarkIteration(commits);
op = geogig.command(LogOp.class).setTopoOrder(true);
for (ObjectId id : ids) {
op.addCommit(id);
}
sw.reset().start();
commits = op.call();
sw.stop();
System.err.println("LogOp using --topo-order took " + sw.toString());
benchmarkIteration(commits);
super.tearDown();
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class EndTransaction 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) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("There isn't a transaction to end.");
}
final Context transaction = this.getCommandLocator(context);
TransactionEnd endTransaction = context.getGeoGIG().command(TransactionEnd.class);
try {
final boolean closed = endTransaction.setCancel(cancel).setTransaction((GeogigTransaction) transaction).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
if (closed) {
out.writeTransactionId(null);
} else {
out.writeTransactionId(getTransactionId());
}
out.finish();
}
});
} catch (MergeConflictsException m) {
final RevCommit ours = context.getGeoGIG().getRepository().getCommit(m.getOurs());
final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(m.getTheirs());
final Optional<ObjectId> ancestor = transaction.command(FindCommonAncestor.class).setLeft(ours).setRight(theirs).call();
context.setResponseContent(new CommandResponse() {
final MergeScenarioReport report = transaction.command(ReportMergeScenarioOp.class).setMergeIntoCommit(ours).setToMergeCommit(theirs).call();
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
Optional<RevCommit> mergeCommit = Optional.absent();
out.writeMergeResponse(mergeCommit, report, transaction, ours.getId(), theirs.getId(), ancestor.get());
out.finish();
}
});
} catch (RebaseConflictsException r) {
// TODO: Handle rebase exception
}
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class Log method writeCSV.
private void writeCSV(GeoGIG geogig, Writer out, Iterator<RevCommit> log) throws Exception {
String response = "ChangeType,FeatureId,CommitId,Parent CommitIds,Author Name,Author Email,Author Commit Time,Committer Name,Committer Email,Committer Commit Time,Commit Message";
out.write(response);
response = "";
String path = paths.get(0);
// This is the feature type object
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(path).setParent(geogig.getRepository().workingTree().getTree()).call();
Optional<RevObject> type = Optional.absent();
if (ref.isPresent()) {
type = geogig.command(RevObjectParse.class).setRefSpec(ref.get().getMetadataId().toString()).call();
} else {
throw new CommandSpecException("Couldn't resolve the given path.");
}
if (type.isPresent() && type.get() instanceof RevFeatureType) {
RevFeatureType featureType = (RevFeatureType) type.get();
Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
int attributeLength = attribs.size();
for (PropertyDescriptor attrib : attribs) {
response += "," + escapeCsv(attrib.getName().toString());
}
response += '\n';
out.write(response);
response = "";
RevCommit commit = null;
while (log.hasNext()) {
commit = log.next();
String parentId = commit.getParentIds().size() >= 1 ? commit.getParentIds().get(0).toString() : ObjectId.NULL.toString();
Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId().toString()).setFilter(path).call();
while (diff.hasNext()) {
DiffEntry entry = diff.next();
response += entry.changeType().toString() + ",";
String fid = "";
if (entry.newPath() != null) {
if (entry.oldPath() != null) {
fid = entry.oldPath() + " -> " + entry.newPath();
} else {
fid = entry.newPath();
}
} else if (entry.oldPath() != null) {
fid = entry.oldPath();
}
response += fid + ",";
response += commit.getId().toString() + ",";
response += parentId;
if (commit.getParentIds().size() > 1) {
for (int index = 1; index < commit.getParentIds().size(); index++) {
response += " " + commit.getParentIds().get(index).toString();
}
}
response += ",";
if (commit.getAuthor().getName().isPresent()) {
response += escapeCsv(commit.getAuthor().getName().get());
}
response += ",";
if (commit.getAuthor().getEmail().isPresent()) {
response += escapeCsv(commit.getAuthor().getEmail().get());
}
response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format(new Date(commit.getAuthor().getTimestamp())) + ",";
if (commit.getCommitter().getName().isPresent()) {
response += escapeCsv(commit.getCommitter().getName().get());
}
response += ",";
if (commit.getCommitter().getEmail().isPresent()) {
response += escapeCsv(commit.getCommitter().getEmail().get());
}
response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format(new Date(commit.getCommitter().getTimestamp())) + ",";
String message = escapeCsv(commit.getMessage());
response += message;
if (entry.newObjectId() == ObjectId.NULL) {
// Feature was removed so we need to fill out blank attribute values
for (int index = 0; index < attributeLength; index++) {
response += ",";
}
} else {
// Feature was added or modified so we need to write out the
// attribute
// values from the feature
Optional<RevObject> feature = geogig.command(RevObjectParse.class).setObjectId(entry.newObjectId()).call();
RevFeature revFeature = (RevFeature) feature.get();
List<Optional<Object>> values = revFeature.getValues();
for (int index = 0; index < values.size(); index++) {
Optional<Object> value = values.get(index);
PropertyDescriptor attrib = (PropertyDescriptor) attribs.toArray()[index];
String stringValue = "";
if (value.isPresent()) {
FieldType attributeType = FieldType.forBinding(attrib.getType().getBinding());
switch(attributeType) {
case DATE:
stringValue = new SimpleDateFormat("MM/dd/yyyy z").format((java.sql.Date) value.get());
break;
case DATETIME:
stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Date) value.get());
break;
case TIME:
stringValue = new SimpleDateFormat("HH:mm:ss z").format((Time) value.get());
break;
case TIMESTAMP:
stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Timestamp) value.get());
break;
default:
stringValue = escapeCsv(value.get().toString());
}
response += "," + stringValue;
} else {
response += ",";
}
}
}
response += '\n';
out.write(response);
response = "";
}
}
} else {
// Couldn't resolve FeatureType
throw new CommandSpecException("Couldn't resolve the given path to a feature type.");
}
}
Aggregations