use of org.locationtech.geogig.api.plumbing.DiffFeature in project GeoGig by boundlessgeo.
the class BlameOp method _call.
@Override
protected BlameReport _call() {
String fullPath = (commit != null ? commit.toString() : Ref.HEAD) + ":" + path;
Optional<ObjectId> id = command(RevParse.class).setRefSpec(fullPath).call();
if (!id.isPresent()) {
throw new BlameException(StatusCode.FEATURE_NOT_FOUND);
}
TYPE type = command(ResolveObjectType.class).setObjectId(id.get()).call();
if (!type.equals(TYPE.FEATURE)) {
throw new BlameException(StatusCode.PATH_NOT_FEATURE);
}
Optional<RevFeatureType> featureType = command(ResolveFeatureType.class).setRefSpec(path).call();
BlameReport report = new BlameReport(featureType.get());
Iterator<RevCommit> log = command(LogOp.class).addPath(path).setUntil(commit).call();
RevCommit commit = log.next();
RevObjectParse revObjectParse = command(RevObjectParse.class);
DiffOp diffOp = command(DiffOp.class);
DiffFeature diffFeature = command(DiffFeature.class);
while (!report.isComplete()) {
if (!log.hasNext()) {
String refSpec = commit.getId().toString() + ":" + path;
RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
report.setFirstVersion(feature, commit);
break;
}
RevCommit commitB = log.next();
Iterator<DiffEntry> diffs = diffOp.setNewVersion(commit.getId()).setOldVersion(commitB.getId()).setReportTrees(false).call();
while (diffs.hasNext()) {
DiffEntry diff = diffs.next();
if (path.equals(diff.newPath())) {
if (diff.isAdd()) {
String refSpec = commit.getId().toString() + ":" + path;
RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
report.setFirstVersion(feature, commit);
break;
}
FeatureDiff featureDiff = diffFeature.setNewVersion(Suppliers.ofInstance(diff.getNewObject())).setOldVersion(Suppliers.ofInstance(diff.getOldObject())).call();
Map<PropertyDescriptor, AttributeDiff> attribDiffs = featureDiff.getDiffs();
Iterator<PropertyDescriptor> iter = attribDiffs.keySet().iterator();
while (iter.hasNext()) {
PropertyDescriptor key = iter.next();
Optional<?> value = attribDiffs.get(key).getNewValue();
String attribute = key.getName().toString();
report.addDiff(attribute, value, commit);
}
}
}
commit = commitB;
}
return report;
}
Aggregations