}
@Override
public synchronized void merge() {
if (parent != null) {
NodeState before = new SegmentNodeState(store, base);
NodeState after = new SegmentNodeState(store, head);
SegmentWriter writer = new SegmentWriter(store);
while (!parent.setHead(base, head)) {
RecordId newBase = parent.getHead();
NodeBuilder builder =
new SegmentNodeState(store, newBase).builder();
after.compareAgainstBaseState(before, new MergeDiff(builder));
NodeState state = builder.getNodeState();
RecordId newHead = writer.writeNode(state).getRecordId();
writer.flush();
base = newBase;