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;
}
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;
}
};
}
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));
}
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));
}
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);
}
Aggregations