Search in sources :

Example 66 with DiffEntry

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());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 67 with DiffEntry

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());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) OSMImportOp(org.locationtech.geogig.osm.internal.OSMImportOp) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) File(java.io.File) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 68 with DiffEntry

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);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 69 with DiffEntry

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);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 70 with DiffEntry

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;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) List(java.util.List) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)83 ObjectId (org.locationtech.geogig.api.ObjectId)38 Test (org.junit.Test)31 RevCommit (org.locationtech.geogig.api.RevCommit)31 NodeRef (org.locationtech.geogig.api.NodeRef)24 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)17 RevFeature (org.locationtech.geogig.api.RevFeature)15 RevTree (org.locationtech.geogig.api.RevTree)15 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)14 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)14 RevObject (org.locationtech.geogig.api.RevObject)11 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)11 Feature (org.opengis.feature.Feature)10 Optional (com.google.common.base.Optional)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)8 Repository (org.locationtech.geogig.repository.Repository)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)8 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 IOException (java.io.IOException)5