@Override public DiffEntry apply(NodeRef treeRef) { return new DiffEntry(treeRef, null); }};
@Override public boolean feature(NodeRef left, NodeRef right) { if (!finished && reportFeatures) { try { entries.put(new DiffEntry(left, right)); } catch (InterruptedException e) { // throw new RuntimeException(e); } } return true; }
public @Override boolean tree(@Nullable NodeRef left, @Nullable NodeRef right) { if (null == (left == null ? right : left).getParentPath()) { return true; } queue.add(new DiffEntry(left, right)); return true; } };
public 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); }
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); }
@Override public DiffEntry read(DataInputStream in) throws IOException { NodeRef left = readRef(in); NodeRef right = readRef(in); DiffEntry e = new DiffEntry(left, right); return e; }
@Override public boolean tree(NodeRef left, NodeRef right) { final String parentPath = left == null ? right.getParentPath() : left.getParentPath(); if (!finished && reportTrees) { if (parentPath != null) {// do not report the root tree try { entries.put(new DiffEntry(left, right)); } catch (InterruptedException e) { // throw new RuntimeException(e); // die gracefully return false; } } } if (recursive) { return !finished; } return parentPath == null; }
@Override public DiffEntry apply(String featurePath) { Node node = RevObjectFactory.defaultInstance().createNode( NodeRef.nodeFromPath(featurePath), ObjectId.NULL, ObjectId.NULL, TYPE.FEATURE, null, null); String parentPath = NodeRef.parentPath(featurePath); NodeRef oldFeature = new NodeRef(node, parentPath, ObjectId.NULL); return new DiffEntry(oldFeature, null); }};
@Test public void testNullNodeRef() throws IOException { // null parent path is only allowed for NodeRef.ROOT named nodes Node rn = RevObjectTestSupport.featureNode("testNode", 2); ObjectId metadataId = RevObjectTestSupport.hashString("test"); NodeRef left = null; NodeRef right = new NodeRef(rn, "parent/path", metadataId); DiffEntry entry = new DiffEntry(left, right); serializer.write(out, entry); byte[] array = stream.toByteArray(); DiffEntry read = serializer.read(new DataInputStream(new ByteArrayInputStream(array))); assertEquals(entry, read); }
@Test public void testFullEntry() throws IOException { Node ln = RevObjectTestSupport.featureNode("testNode", 1); Node rn = RevObjectTestSupport.featureNode("testNode", 2); ObjectId metadataId = RevObjectTestSupport.hashString("test"); NodeRef left = new NodeRef(ln, "parent/path", metadataId); NodeRef right = new NodeRef(rn, "parent/path", metadataId); DiffEntry entry = new DiffEntry(left, right); serializer.write(out, entry); byte[] array = stream.toByteArray(); DiffEntry read = serializer.read(new DataInputStream(new ByteArrayInputStream(array))); assertEquals(entry, read); }
private List<DiffEntry> findWithLsTreeOp(RevTree left, RevTree right) { LsTreeOp lstreeOld = repo.command(LsTreeOp.class) .setStrategy(Strategy.DEPTHFIRST_ONLY_TREES).setReference(left.getId().toString()); LsTreeOp lstreeNew = repo.command(LsTreeOp.class) .setStrategy(Strategy.DEPTHFIRST_ONLY_TREES).setReference(right.getId().toString()); Iterator<NodeRef> oldtrees = lstreeOld.call(); Iterator<NodeRef> newtrees = lstreeNew.call(); ImmutableMap<String, NodeRef> oldtreemap = Maps.uniqueIndex(oldtrees, (r) -> r.path()); ImmutableMap<String, NodeRef> newtreemap = Maps.uniqueIndex(newtrees, (r) -> r.path()); MapDifference<String, NodeRef> difference = Maps.difference(oldtreemap, newtreemap); List<DiffEntry> res = new ArrayList<>(); difference.entriesOnlyOnLeft().forEach((p, e) -> res.add(new DiffEntry(e, null))); difference.entriesOnlyOnRight().forEach((p, e) -> res.add(new DiffEntry(null, e))); difference.entriesDiffering() .forEach((p, v) -> res.add(new DiffEntry(v.leftValue(), v.rightValue()))); return res; }
private void printConflictDiff(Conflict conflict, Console console, GeoGIG geogig) throws IOException { FullDiffPrinter diffPrinter = new FullDiffPrinter(false, true); console.println("---" + conflict.getPath() + "---"); ObjectId theirsHeadId = getTheirsHeadId(); Optional<RevCommit> theirsHead = geogig.command(RevObjectParse.class) .setObjectId(theirsHeadId).call(RevCommit.class); ObjectId oursHeadId = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call().get() .getObjectId(); Optional<RevCommit> oursHead = geogig.command(RevObjectParse.class).setObjectId(oursHeadId) .call(RevCommit.class); Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class) .setLeft(theirsHead.get()).setRight(oursHead.get()).call(); String ancestorPath = commonAncestor.get().toString() + ":" + conflict.getPath(); Optional<NodeRef> ancestorNodeRef = geogig.command(FeatureNodeRefFromRefspec.class) .setRefspec(ancestorPath).call(); String path = Ref.ORIG_HEAD + ":" + conflict.getPath(); Optional<NodeRef> oursNodeRef = geogig.command(FeatureNodeRefFromRefspec.class) .setRefspec(path).call(); DiffEntry diffEntry = new DiffEntry(ancestorNodeRef.orNull(), oursNodeRef.orNull()); console.println("Ours"); diffPrinter.print(geogig, console, diffEntry); path = theirsHeadId + ":" + conflict.getPath(); Optional<NodeRef> theirsNodeRef = geogig.command(FeatureNodeRefFromRefspec.class) .setRefspec(path).call(); diffEntry = new DiffEntry(ancestorNodeRef.orNull(), theirsNodeRef.orNull()); console.println("Theirs"); diffPrinter.print(geogig, console, diffEntry); }
@Test public void testNoDefaultMetadataId() throws IOException { // null parent path is only allowed for NodeRef.ROOT named nodes Node ln = RevObjectFactory.defaultInstance().createNode(NodeRef.ROOT, RevTree.EMPTY_TREE_ID, ObjectId.NULL, TYPE.TREE, new Envelope(0, 0, 0, 0), null); Node rn = RevObjectFactory.defaultInstance().createNode(NodeRef.ROOT, RevObjectTestSupport.hashString("rnd"), ObjectId.NULL, TYPE.TREE, new Envelope(0, 1, 0, 1), null); ObjectId metadataId = ObjectId.NULL; NodeRef left = new NodeRef(ln, null, metadataId); NodeRef right = new NodeRef(rn, null, metadataId); DiffEntry entry = new DiffEntry(left, right); serializer.write(out, entry); byte[] array = stream.toByteArray(); DiffEntry read = serializer.read(new DataInputStream(new ByteArrayInputStream(array))); assertEquals(entry, read); }
NodeRef right = new NodeRef(rn, "parent/path", metadataId); DiffEntry entry = new DiffEntry(left, right); expected.add(entry);
@Test public void testFullEntryNullParentPath() throws IOException { // null parent path is only allowed for NodeRef.ROOT named nodes Node ln = RevObjectFactory.defaultInstance().createNode(NodeRef.ROOT, RevTree.EMPTY_TREE_ID, ObjectId.NULL, TYPE.TREE, new Envelope(0, 0, 0, 0), null); Node rn = RevObjectFactory.defaultInstance().createNode(NodeRef.ROOT, RevObjectTestSupport.hashString("rnd"), ObjectId.NULL, TYPE.TREE, new Envelope(0, 1, 0, 1), null); ObjectId metadataId = RevObjectTestSupport.hashString("test"); NodeRef left = new NodeRef(ln, null, metadataId); NodeRef right = new NodeRef(rn, null, metadataId); DiffEntry entry = new DiffEntry(left, right); serializer.write(out, entry); byte[] array = stream.toByteArray(); DiffEntry read = serializer.read(new DataInputStream(new ByteArrayInputStream(array))); assertEquals(entry, read); }
@Test public void testToString() { Node node = RevObjectFactory.defaultInstance().createNode("Points.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0000"), ObjectId.valueOf("abc123000000000000001234567890abcdef0010"), TYPE.FEATURE, null, null); NodeRef nodeRef = new NodeRef(node, "Points", ObjectId.NULL); Node node2 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0001"), ObjectId.valueOf("abc123000000000000001234567890abcdef0011"), TYPE.FEATURE, null, null); NodeRef nodeRef2 = new NodeRef(node2, "Lines", ObjectId.NULL); DiffEntry entry = new DiffEntry(nodeRef, null); assertTrue(entry.toString().contains("REMOVED")); assertTrue(entry.toString().contains(nodeRef.toString())); entry = new DiffEntry(null, nodeRef); assertTrue(entry.toString().contains("ADDED")); assertTrue(entry.toString().contains(nodeRef.toString())); entry = new DiffEntry(nodeRef, nodeRef2); assertTrue(entry.toString().contains("MODIFIED")); assertTrue(entry.toString().contains("] -> [")); String[] tokens = entry.toString().split("\\] -> \\["); assertEquals(2, tokens.length); assertTrue(tokens[0].contains(nodeRef.toString())); assertTrue(tokens[1].contains(nodeRef2.toString())); }
@Test public void testHashCode() { Node node = RevObjectFactory.defaultInstance().createNode("Points.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0000"), ObjectId.valueOf("abc123000000000000001234567890abcdef0010"), TYPE.FEATURE, new Envelope(0, 1, 0, 1), null); NodeRef nodeRef = new NodeRef(node, "Points", ObjectId.NULL); Node node2 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0001"), ObjectId.valueOf("abc123000000000000001234567890abcdef0011"), TYPE.FEATURE, new Envelope(1, 2, 1, 2), null); NodeRef nodeRef2 = new NodeRef(node2, "Lines", ObjectId.NULL); DiffEntry entry1 = new DiffEntry(nodeRef, null); DiffEntry entry2 = new DiffEntry(null, nodeRef); DiffEntry entry3 = new DiffEntry(nodeRef, nodeRef2); assertNotSame(entry1.hashCode(), entry2.hashCode()); assertNotSame(entry1.hashCode(), entry3.hashCode()); assertNotSame(entry2.hashCode(), entry3.hashCode()); }
@Test public void testEquals() { Node node = RevObjectFactory.defaultInstance().createNode("Points.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0000"), ObjectId.valueOf("abc123000000000000001234567890abcdef0010"), TYPE.FEATURE, null, null); NodeRef nodeRef = new NodeRef(node, "Points", ObjectId.NULL); Node node2 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0001"), ObjectId.valueOf("abc123000000000000001234567890abcdef0011"), TYPE.FEATURE, null, null); NodeRef nodeRef2 = new NodeRef(node2, "Lines", ObjectId.NULL); DiffEntry entry1 = new DiffEntry(nodeRef, null); DiffEntry entry2 = new DiffEntry(null, nodeRef); DiffEntry entry3 = new DiffEntry(nodeRef, nodeRef2); DiffEntry entry4 = new DiffEntry(nodeRef2, nodeRef); assertEquals(entry1, entry1); assertEquals(entry2, entry2); assertEquals(entry3, entry3); assertEquals(entry4, entry4); assertFalse(entry1.equals(entry2)); assertFalse(entry1.equals(entry3)); assertFalse(entry1.equals(entry4)); assertFalse(entry2.equals(entry3)); assertFalse(entry2.equals(entry4)); assertFalse(entry3.equals(entry4)); assertFalse(entry1.equals(nodeRef)); }
private DiffEntry entry(String name, RevFeature l, RevFeature r) { //@formatter:off Node lnode = l == null? null: RevObjectFactory.defaultInstance().createNode(name, l.getId(), ObjectId.NULL, TYPE.FEATURE, SpatialOps.boundsOf(l), null); Node rnode = r == null? null: RevObjectFactory.defaultInstance().createNode(name, r.getId(), ObjectId.NULL, TYPE.FEATURE, SpatialOps.boundsOf(r), null); //@formatter:on NodeRef oldObject = lnode == null ? null : NodeRef.create(NodeRef.ROOT, lnode); NodeRef newObject = rnode == null ? null : NodeRef.create(NodeRef.ROOT, rnode); return new DiffEntry(oldObject, newObject); }
@Test public void testExpand() { Node node = RevObjectFactory.defaultInstance().createNode("Points.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0000"), ObjectId.valueOf("abc123000000000000001234567890abcdef0010"), TYPE.FEATURE, new Envelope(0, 1, 0, 1), null); NodeRef nodeRef = new NodeRef(node, "Points", ObjectId.NULL); Node node2 = RevObjectFactory.defaultInstance().createNode("Lines.1", ObjectId.valueOf("abc123000000000000001234567890abcdef0001"), ObjectId.valueOf("abc123000000000000001234567890abcdef0011"), TYPE.FEATURE, new Envelope(1, 2, 1, 2), null); NodeRef nodeRef2 = new NodeRef(node2, "Lines", ObjectId.NULL); DiffEntry entry1 = new DiffEntry(nodeRef, null); DiffEntry entry2 = new DiffEntry(null, nodeRef); DiffEntry entry3 = new DiffEntry(nodeRef, nodeRef2); Envelope env = new Envelope(); entry1.expand(env); assertEquals(new Envelope(0, 1, 0, 1), env); env = new Envelope(); entry2.expand(env); assertEquals(new Envelope(0, 1, 0, 1), env); env = new Envelope(); entry3.expand(env); assertEquals(new Envelope(0, 2, 0, 2), env); }