use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class DiffOpTest method testSingleAdditionReverseOrder.
@Test
public void testSingleAdditionReverseOrder() throws Exception {
final ObjectId newOid = insertAndAdd(points1);
final RevCommit commit = geogig.command(CommitOp.class).setAll(true).call();
List<DiffEntry> difflist = toList(diffOp.setOldVersion(commit.getId()).setNewVersion(ObjectId.NULL).call());
assertNotNull(difflist);
assertEquals(1, difflist.size());
DiffEntry de = difflist.get(0);
assertNull(de.getNewObject());
assertNotNull(de.getOldObject());
assertEquals(DiffEntry.ChangeType.REMOVED, de.changeType());
assertEquals(ObjectId.NULL, de.newObjectId());
assertEquals(newOid, de.oldObjectId());
assertFalse(de.getOldObject().getMetadataId().isNull());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class OSMExportTest method testExportAndThenReimport.
@Test
public void testExportAndThenReimport() throws Exception {
String filename = OSMImportOp.class.getResource("fire.xml").getFile();
File filterFile = new File(filename);
cli.execute("osm", "import", filterFile.getAbsolutePath());
cli.execute("add");
cli.execute("commit", "-m", "message");
Optional<ObjectId> id = cli.getGeogig().command(RevParse.class).setRefSpec("HEAD:node").call();
assertTrue(id.isPresent());
id = cli.getGeogig().command(RevParse.class).setRefSpec("HEAD:way").call();
assertTrue(id.isPresent());
File file = new File(tempFolder.getRoot(), "export.xml");
cli.execute("osm", "export", file.getAbsolutePath());
cli.execute("rm", "-r", "node");
cli.execute("rm", "-r", "way");
cli.execute("add");
cli.execute("commit", "-m", "Deleted OSM data");
id = cli.getGeogig().command(RevParse.class).setRefSpec("HEAD:node").call();
assertFalse(id.isPresent());
id = cli.getGeogig().command(RevParse.class).setRefSpec("HEAD:way").call();
assertFalse(id.isPresent());
cli.execute("osm", "import", file.getAbsolutePath());
cli.execute("add");
cli.execute("commit", "-m", "reimport");
Optional<RevTree> tree = cli.getGeogig().command(RevObjectParse.class).setRefSpec("HEAD:node").call(RevTree.class);
assertTrue(tree.isPresent());
assertTrue(tree.get().size() > 0);
tree = cli.getGeogig().command(RevObjectParse.class).setRefSpec("HEAD:way").call(RevTree.class);
assertTrue(tree.isPresent());
assertTrue(tree.get().size() > 0);
Iterator<DiffEntry> diffs = cli.getGeogig().command(DiffOp.class).setNewVersion("HEAD").setOldVersion("HEAD~2").call();
assertFalse(diffs.hasNext());
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class FormatCommonV1 method readDiff.
public static DiffEntry readDiff(DataInput in) throws IOException {
boolean oldNode = in.readBoolean();
NodeRef oldNodeRef = null;
if (oldNode) {
oldNodeRef = readNodeRef(in);
}
boolean newNode = in.readBoolean();
NodeRef newNodeRef = null;
if (newNode) {
newNodeRef = readNodeRef(in);
}
return new DiffEntry(oldNodeRef, newNodeRef);
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class FormatCommonV2 method readDiff.
public static DiffEntry readDiff(DataInput in) throws IOException {
boolean oldNode = in.readBoolean();
NodeRef oldNodeRef = null;
if (oldNode) {
oldNodeRef = readNodeRef(in);
}
boolean newNode = in.readBoolean();
NodeRef newNodeRef = null;
if (newNode) {
newNodeRef = readNodeRef(in);
}
return new DiffEntry(oldNodeRef, newNodeRef);
}
use of org.locationtech.geogig.api.plumbing.diff.DiffEntry in project GeoGig by boundlessgeo.
the class CheckMergeScenarioOp method _call.
@Override
protected Boolean _call() {
if (commits.size() < 2) {
return Boolean.FALSE;
}
Optional<ObjectId> ancestor = command(FindCommonAncestor.class).setLeft(commits.get(0)).setRight(commits.get(1)).call();
Preconditions.checkState(ancestor.isPresent(), "No ancestor commit could be found.");
for (int i = 2; i < commits.size(); i++) {
ancestor = command(FindCommonAncestor.class).setLeft(commits.get(i)).setRightId(ancestor.get()).call();
Preconditions.checkState(ancestor.isPresent(), "No ancestor commit could be found.");
}
Map<String, List<DiffEntry>> diffs = Maps.newHashMap();
Set<String> removedPaths = Sets.newTreeSet();
// we organize the changes made for each path
for (RevCommit commit : commits) {
Iterator<DiffEntry> toMergeDiffs = command(DiffTree.class).setReportTrees(true).setOldTree(ancestor.get()).setNewTree(commit.getId()).call();
while (toMergeDiffs.hasNext()) {
DiffEntry diff = toMergeDiffs.next();
String path = diff.oldPath() == null ? diff.newPath() : diff.oldPath();
if (diffs.containsKey(path)) {
diffs.get(path).add(diff);
} else {
diffs.put(path, Lists.newArrayList(diff));
}
if (ChangeType.REMOVED.equals(diff.changeType())) {
removedPaths.add(path);
}
}
}
// now we check that, for any path, changes are compatible
Collection<List<DiffEntry>> values = diffs.values();
for (List<DiffEntry> list : values) {
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
if (hasConflicts(list.get(i), list.get(j))) {
return true;
}
}
if (!ChangeType.REMOVED.equals(list.get(i).changeType())) {
if (removedPaths.contains(list.get(i).getNewObject().getParentPath())) {
return true;
}
}
}
}
return false;
}
Aggregations