Search in sources :

Example 1 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class FormatCommonV2 method readHeader.

public static TYPE readHeader(DataInput in) throws IOException {
    final int header = in.readByte() & 0xFF;
    checkState(header > -1 && header < 6, "Illegal RevObject type header: %s, must be between 0 and 4 inclusive", Integer.valueOf(header));
    final RevObject.TYPE type = TYPE.valueOf(header);
    return type;
}
Also used : TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevObject(org.locationtech.geogig.api.RevObject)

Example 2 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class HeapObjectDatabse method getAll.

@Override
public Iterator<RevObject> getAll(final Iterable<ObjectId> ids, final BulkOpListener listener) {
    return new AbstractIterator<RevObject>() {

        final Iterator<ObjectId> iterator = ids.iterator();

        @Override
        protected RevObject computeNext() {
            RevObject found = null;
            ObjectId id;
            byte[] raw;
            while (iterator.hasNext() && found == null) {
                id = iterator.next();
                raw = objects.get(id);
                if (raw != null) {
                    try {
                        found = serializationFactory.createObjectReader().read(id, new LZFInputStream(new ByteArrayInputStream(raw)));
                    } catch (IOException e) {
                        throw Throwables.propagate(e);
                    }
                    listener.found(found.getId(), raw.length);
                } else {
                    listener.notFound(id);
                }
            }
            return found == null ? endOfData() : found;
        }
    };
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) LZFInputStream(com.ning.compress.lzf.LZFInputStream) AbstractIterator(com.google.common.collect.AbstractIterator) IOException(java.io.IOException)

Example 3 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method testPushSparseMerge.

@Test
public void testPushSparseMerge() throws Exception {
    setupSparseClone();
    // create a branch off an early commit
    Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
    RevCommit initialCommit = logs.next();
    ObjectId masterCommit = initialCommit.getId();
    while (logs.hasNext()) {
        initialCommit = logs.next();
    }
    localGeogig.geogig.command(BranchCreateOp.class).setName("Branch1").setAutoCheckout(true).setSource(initialCommit.getId().toString()).call();
    // Add some commits to the local (sparse) repository
    List<Feature> features = Arrays.asList(city1, city1_modified, road3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(localGeogig.geogig, f);
        oids.put(f, oId);
        final RevCommit commit = localGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = localGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Merge master into Branch1
    MergeOp merge = localGeogig.geogig.command(MergeOp.class);
    MergeReport report = merge.addCommit(Suppliers.ofInstance(masterCommit)).setMessage("Merge").call();
    // Update master to the new merge commit
    localGeogig.geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(report.getMergeCommit().getId()).call();
    // Checkout master
    localGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
    PushOp push = push();
    push.addRefSpec("refs/heads/master").call();
    logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals("Merge", logged.get(0).getMessage());
    assertFalse(report.getMergeCommit().getId().equals(logged.get(0).getId()));
    // Although we merged "Roads.2" commit into the "Roads.3" commit, making the "Roads.2"
    // commit the second parent, they should have been swapped when pushing to the full
    // repository to prevent any sparse data from being lost.
    ObjectId parent1Id = logged.get(0).getParentIds().get(0);
    ObjectId parent2Id = logged.get(0).getParentIds().get(1);
    RevCommit parent1 = remoteGeogig.geogig.getRepository().getCommit(parent1Id);
    assertNotNull(parent1);
    assertEquals("Roads.2", parent1.getMessage());
    RevCommit parent2 = remoteGeogig.geogig.getRepository().getCommit(parent2Id);
    assertNotNull(parent2);
    assertEquals("Roads.3", parent2.getMessage());
    // Verify they weren't swapped in the original
    parent1Id = report.getMergeCommit().getParentIds().get(0);
    parent2Id = report.getMergeCommit().getParentIds().get(1);
    parent1 = localGeogig.geogig.getRepository().getCommit(parent1Id);
    assertNotNull(parent1);
    assertEquals("Roads.3", parent1.getMessage());
    parent2 = localGeogig.geogig.getRepository().getCommit(parent2Id);
    assertNotNull(parent2);
    assertEquals("Roads.2", parent2.getMessage());
    assertExists(remoteGeogig, oids.get(city1), oids.get(city1_modified), oids.get(road3));
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) HashMap(java.util.HashMap) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) PushOp(org.locationtech.geogig.api.porcelain.PushOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 4 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method testSparseCloneAllMatch.

@Test
public void testSparseCloneAllMatch() throws Exception {
    Map<String, String> filter = new HashMap<String, String>();
    filter.put("default", "BBOX(pp,0, -125, 40, -70,'EPSG:4326')");
    createFilterFile(filter);
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(city1, city2, city3, road1, road2, road3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        oids.put(f, oId);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(0);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).setBranch("master").call();
    // Because all features match the filter, the history should be identical
    // Make sure the local repository got the correct commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    assertExists(localGeogig, oids.get(city1), oids.get(city2), oids.get(city3), oids.get(road1), oids.get(road2), oids.get(road3));
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) HashMap(java.util.HashMap) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 5 with RevObject

use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.

the class SparseCloneTest method testPullCommitThatPassesFilter.

@Test
public void testPullCommitThatPassesFilter() throws Exception {
    setupSparseClone();
    // Add a commit that passes our filter to the remote.
    ObjectId oId = insertAndAdd(remoteGeogig.geogig, city1_modified);
    final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(city1_modified.getIdentifier().toString()).call();
    Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
    assertTrue(childObject.isPresent());
    assertEquals(commit, remoteGeogig.geogig.getRepository().objectDatabase().getCommit(commit.getId()));
    PullOp pull = pull();
    pull.call();
    Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals("Cities.1", logged.get(0).getMessage());
    assertFalse(commit.getId().equals(logged.get(0).getId()));
    assertExists(localGeogig, oId);
}
Also used : PullOp(org.locationtech.geogig.api.porcelain.PullOp) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8