DBObject id = new BasicDBObject("_id", name);
DBObject state = journals.findOne(id, null, primaryPreferred());
checkState(state != null);
if (state.containsField("parent")) {
RecordId base = RecordId.fromString(state.get("base").toString());
RecordId head = RecordId.fromString(state.get("head").toString());
SegmentWriter writer = store.getWriter();
Segment segment = writer.getDummySegment();
NodeState before = new SegmentNodeState(segment, base);
NodeState after = new SegmentNodeState(segment, head);
Journal parent = store.getJournal(state.get("parent").toString());
while (!parent.setHead(base, head)) {
RecordId newBase = parent.getHead();
NodeBuilder builder =
new SegmentNodeState(segment, newBase).builder();
after.compareAgainstBaseState(before, new MergeDiff(builder));
RecordId newHead =
writer.writeNode(builder.getNodeState()).getRecordId();
base = newBase;
head = newHead;
}