use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class PatchSerializer method write.
public static void write(Writer w, Patch patch) throws IOException {
StringBuilder sb = new StringBuilder();
List<RevFeatureType> featureTypes = patch.getFeatureTypes();
for (RevFeatureType featureType : featureTypes) {
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
writer.write(featureType, output);
sb.append(output.toString());
sb.append('\n');
}
TextSerializationFactory factory = new TextSerializationFactory();
for (FeatureInfo feature : patch.getAddedFeatures()) {
String path = feature.getPath();
sb.append("A\t" + path + "\t" + feature.getFeatureType().getId() + "\n");
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature());
try {
writer.write(revFeature, output);
} catch (IOException e) {
}
sb.append(output.toString());
sb.append('\n');
}
for (FeatureInfo feature : patch.getRemovedFeatures()) {
String path = feature.getPath();
sb.append("R\t" + path + "\t" + feature.getFeatureType().getId() + "\n");
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature());
try {
writer.write(revFeature, output);
} catch (IOException e) {
}
sb.append(output.toString());
sb.append('\n');
}
for (FeatureDiff diff : patch.getModifiedFeatures()) {
sb.append("M\t" + diff.getPath() + "\t" + diff.getOldFeatureType().getId().toString() + "\t" + diff.getNewFeatureType().getId().toString() + "\n");
sb.append(diff.asText() + "\n");
}
for (FeatureTypeDiff diff : patch.getAlteredTrees()) {
sb.append(diff.toString() + "\n");
}
w.write(sb.toString());
w.flush();
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class RebaseOpTest method testRebaseSquash.
@Test
public void testRebaseSquash() throws Exception {
// Create the following revision graph
// o
// |
// o - master - Points 1 added
// |\
// | o - branch1 - Points 2 added
// |
// o - Points 3 added
// |
// o - branch2 - HEAD - Lines 1 added
insertAndAdd(points1);
final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// create branch1 and checkout
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
// checkout master, then create branch2 and checkout
geogig.command(CheckoutOp.class).setSource("master").call();
final Ref branch2 = geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
insertAndAdd(points3);
final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
insertAndAdd(lines1);
final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).setSquashMessage("squashed commit").call();
CheckoutResult result;
result = geogig.command(CheckoutOp.class).setSource("branch1").call();
assertEquals(c2.getTreeId(), result.getNewTree());
assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
assertEquals(branch1.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()).getTarget());
result = geogig.command(CheckoutOp.class).setSource("branch2").call();
assertFalse(c4.getTreeId().equals(result.getNewTree()));
assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
assertEquals(branch2.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()).getTarget());
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
// Commit 4
RevCommit logC4 = log.next();
assertEquals(c4.getAuthor(), logC4.getAuthor());
assertEquals(c4.getCommitter().getName(), logC4.getCommitter().getName());
assertEquals(c4.getCommitter().getEmail(), logC4.getCommitter().getEmail());
assertEquals("squashed commit", logC4.getMessage());
assertEquals(c4.getAuthor().getTimeZoneOffset(), logC4.getAuthor().getTimeZoneOffset());
assertEquals(c4.getAuthor().getTimestamp(), logC4.getAuthor().getTimestamp());
assertEquals(c4.getCommitter().getTimeZoneOffset(), logC4.getCommitter().getTimeZoneOffset());
assertFalse(c4.getCommitter().getTimestamp() == logC4.getCommitter().getTimestamp());
assertFalse(c4.getTreeId().equals(logC4.getTreeId()));
String path = NodeRef.appendChild(linesName, idL1);
Optional<RevFeature> lines = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(lines.isPresent());
path = NodeRef.appendChild(pointsName, idP3);
Optional<RevFeature> points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(points.isPresent());
// Commit 2
RevCommit logC2 = log.next();
assertEquals(c2.getAuthor(), logC2.getAuthor());
assertEquals(c2.getCommitter().getName(), logC2.getCommitter().getName());
assertEquals(c2.getMessage(), logC2.getMessage());
assertEquals(c2.getAuthor().getTimeZoneOffset(), logC2.getAuthor().getTimeZoneOffset());
assertEquals(c2.getAuthor().getTimestamp(), logC2.getAuthor().getTimestamp());
assertEquals(c2.getCommitter().getTimeZoneOffset(), logC2.getCommitter().getTimeZoneOffset());
assertEquals(c2.getCommitter().getTimestamp(), logC2.getCommitter().getTimestamp());
assertEquals(c2.getTreeId(), logC2.getTreeId());
// Commit 1
RevCommit logC1 = log.next();
assertEquals(c1.getAuthor(), logC1.getAuthor());
assertEquals(c1.getCommitter().getName(), logC1.getCommitter().getName());
assertEquals(c1.getMessage(), logC1.getMessage());
assertEquals(c1.getAuthor().getTimeZoneOffset(), logC1.getAuthor().getTimeZoneOffset());
assertEquals(c1.getAuthor().getTimestamp(), logC1.getAuthor().getTimestamp());
assertEquals(c1.getCommitter().getTimeZoneOffset(), logC1.getCommitter().getTimeZoneOffset());
assertEquals(c1.getCommitter().getTimestamp(), logC1.getCommitter().getTimestamp());
assertEquals(c1.getTreeId(), logC1.getTreeId());
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class RebaseOpTest method testRebaseSquashWithConflict.
@Test
public void testRebaseSquashWithConflict() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1,2 added
// |\
// | o - branch1 - Points 1 modifiedB, 2 removed, 3 added
// |
// o - Points 1 modified, 2 removed
// |
// o - master - HEAD - Lines 1 added
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("branch1").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insert(points1Modified);
delete(points2);
geogig.command(AddOp.class).call();
RevCommit masterCommit2 = geogig.command(CommitOp.class).setMessage("adding points1 modified, deleting point2").call();
insert(lines1);
geogig.command(AddOp.class).call();
RevCommit masterCommit = geogig.command(CommitOp.class).setMessage("adding lines.1").call();
geogig.command(CheckoutOp.class).setSource("branch1").call();
insert(points3);
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
delete(points2);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).setMessage("branch commit").call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
try {
geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).setSquashMessage("squashed commit").call();
fail();
} catch (RebaseConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(masterCommit.getId(), ref.get().getObjectId());
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
assertEquals(1, conflicts.size());
String path = NodeRef.appendChild(pointsName, idP1);
assertEquals(conflicts.get(0).getPath(), path);
assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1Modified).getId());
assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
// solve, and continue
Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Merged);
geogig.command(AddOp.class).call();
geogig.command(RebaseOp.class).setContinue(true).call();
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
RevCommit logCommit1 = log.next();
assertEquals(masterCommit.getAuthor(), logCommit1.getAuthor());
assertEquals(masterCommit.getCommitter().getName(), logCommit1.getCommitter().getName());
assertEquals("squashed commit", logCommit1.getMessage());
assertEquals(masterCommit.getAuthor().getTimeZoneOffset(), logCommit1.getAuthor().getTimeZoneOffset());
assertEquals(masterCommit.getAuthor().getTimestamp(), logCommit1.getAuthor().getTimestamp());
assertEquals(masterCommit.getCommitter().getTimeZoneOffset(), logCommit1.getCommitter().getTimeZoneOffset());
assertNotSame(masterCommit.getCommitter().getTimestamp(), logCommit1.getCommitter().getTimestamp());
assertNotSame(masterCommit.getTreeId(), logCommit1.getTreeId());
RevCommit logCommit3 = log.next();
assertEquals(branchCommit.getAuthor(), logCommit3.getAuthor());
assertEquals(branchCommit.getCommitter().getName(), logCommit3.getCommitter().getName());
assertEquals(branchCommit.getMessage(), logCommit3.getMessage());
path = NodeRef.appendChild(linesName, idL1);
Optional<RevFeature> lines = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(lines.isPresent());
path = NodeRef.appendChild(pointsName, idP3);
Optional<RevFeature> points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(points.isPresent());
path = NodeRef.appendChild(pointsName, idP1);
points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(points.isPresent());
assertEquals(RevFeatureBuilder.build(points1Merged), points.get());
ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertFalse(ref.isPresent());
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class RebaseOpTest method testRebaseSkip.
@Test
public void testRebaseSkip() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1,2 added
// |\
// | o - branch1 - Points 1 modifiedB, 2 removed, 3 added
// |
// o - Points 1 modified, 2 removed
// |
// o - master - HEAD - Lines 1 added
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("branch1").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insert(points1Modified);
delete(points2);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("adding points1 modified, deleting point2").call();
insert(lines1);
geogig.command(AddOp.class).call();
RevCommit masterCommit = geogig.command(CommitOp.class).setMessage("adding lines.1").call();
geogig.command(CheckoutOp.class).setSource("branch1").call();
insert(points3);
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
delete(points2);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).setMessage("branch commit").call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
try {
geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).call();
fail();
} catch (RebaseConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
String path = NodeRef.appendChild(pointsName, idP1);
Optional<RevFeature> points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(points.isPresent());
assertEquals(RevFeatureBuilder.build(points1ModifiedB), points.get());
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
assertFalse(conflicts.isEmpty());
geogig.command(RebaseOp.class).setSkip(true).call();
conflicts = geogig.command(ConflictsReadOp.class).call();
assertTrue(conflicts.isEmpty());
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
RevCommit logCommit1 = log.next();
assertEquals(masterCommit.getAuthor(), logCommit1.getAuthor());
assertEquals(masterCommit.getCommitter().getName(), logCommit1.getCommitter().getName());
assertEquals(masterCommit.getMessage(), logCommit1.getMessage());
assertEquals(masterCommit.getAuthor().getTimeZoneOffset(), logCommit1.getAuthor().getTimeZoneOffset());
assertEquals(masterCommit.getAuthor().getTimestamp(), logCommit1.getAuthor().getTimestamp());
assertEquals(masterCommit.getCommitter().getTimeZoneOffset(), logCommit1.getCommitter().getTimeZoneOffset());
assertNotSame(masterCommit.getCommitter().getTimestamp(), logCommit1.getCommitter().getTimestamp());
assertNotSame(masterCommit.getTreeId(), logCommit1.getTreeId());
RevCommit logCommit2 = log.next();
assertEquals(branchCommit.getAuthor(), logCommit2.getAuthor());
assertEquals(branchCommit.getCommitter().getName(), logCommit2.getCommitter().getName());
assertEquals(branchCommit.getMessage(), logCommit2.getMessage());
// check that the changes from conflicting commit haven't been introduced
points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(points.isPresent());
assertEquals(RevFeatureBuilder.build(points1ModifiedB), points.get());
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertFalse(ref.isPresent());
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeConflictingBranchesOurs.
@Test
public void testMergeConflictingBranchesOurs() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - TestBranch - Points 1 modified and points 2 added
// |
// o - master - HEAD - Points 1 modifiedB
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insertAndAdd(points1ModifiedB);
insertAndAdd(points2);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).setOurs(true).call();
String path = NodeRef.appendChild(pointsName, idP1);
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
assertEquals(RevFeatureBuilder.build(points1Modified), revFeature.get());
path = NodeRef.appendChild(pointsName, idP2);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
assertEquals(RevFeatureBuilder.build(points2), revFeature.get());
}
Aggregations