Skip to content

Commit

Permalink
[fix] Merge content of both pred and succ, fix #82
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse committed Mar 23, 2020
1 parent d712483 commit 69b5816
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/main/java/se/kth/spork/base3dm/TdmMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public static <T extends ListNode,V> void resolveRawMerge(ChangeSet<T,V> base, C
if (!delta.contains(pcs)) // was removed as otherPcs
continue;

if (!pcs.getPredecessor().isListEdge()) {
Set<Content<T,V>> contents = delta.getContent(pcs.getPredecessor());
if (contents != null && contents.size() > 1) {
Set<Content<T,V>> newContent = handleContentConflict(contents, base);
delta.setContent(pcs.getPredecessor(), newContent);
}
}
// We need to merge the content of the predecessor and successor, but we can skip the parent.
// The reason is that a parent node that never appears as a predecessor or successor will never be
// processed when converting from PCS to tree, with the exception of the virtual root (which has no content).
// It is however possible for a node to only appear as predecessor or successor in certain conflict
// situations, see https://github.com/kth/spork/issues/82 for details
mergeContent(pcs.getPredecessor(), base, delta);
mergeContent(pcs.getSuccessor(), base, delta);

Optional<Pcs<T>> other = delta.getOtherRoot(pcs);
if (!other.isPresent())
Expand Down Expand Up @@ -65,6 +65,17 @@ public static <T extends ListNode,V> void resolveRawMerge(ChangeSet<T,V> base, C
}
}

/**
* Merge the content of a node, if possible.
*/
private static <T extends ListNode,V> void mergeContent(T node, ChangeSet<T,V> base, ChangeSet<T,V> delta) {
Set<Content<T,V>> contents = delta.getContent(node);
if (contents != null && contents.size() > 1) {
Set<Content<T,V>> newContent = handleContentConflict(contents, base);
delta.setContent(node, newContent);
}
}

/**
* Handle content conflicts, i.e. the same node is associated with multiple (potentially equivalent) contents.
*
Expand Down

0 comments on commit 69b5816

Please sign in to comment.