Skip to content

Commit

Permalink
Reduce conflicts when base is empty and lines on top or bottom match
Browse files Browse the repository at this point in the history
  • Loading branch information
yairchu committed Dec 9, 2019
1 parent fc98861 commit 66e8148
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Resolution.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,21 @@ resolveConflict conflict@Conflict{..}
| cBodyA == cBodyB = Resolution $ unlines cBodyA
| matchTop > 0 || matchBottom > 0 =
PartialResolution $ unlines $
take matchTop cBodyBase ++
take matchTop cBodyA ++
Conflict.prettyLines conflict
{ cBodyA = unmatched cBodyA
, cBodyBase = unmatched cBodyBase
, cBodyB = unmatched cBodyB
} ++
takeEnd matchBottom cBodyBase
takeEnd matchBottom cBodyA
| otherwise = NoResolution
where
matchTop =
minimum $ map (lengthOfCommonPrefix cBodyBase) [cBodyA, cBodyB]
match base a b
| null base = lengthOfCommonPrefix a b
| otherwise = minimum $ map (lengthOfCommonPrefix base) [a, b]
matchTop = match cBodyBase cBodyA cBodyB
revBottom = reverse . drop matchTop
revBottomBase = revBottom cBodyBase
matchBottom =
minimum $
map (lengthOfCommonPrefix revBottomBase . revBottom)
[cBodyA, cBodyB]
matchBottom = match (revBottom cBodyBase) (revBottom cBodyA) (revBottom cBodyB)
dropEnd count xs = take (length xs - count) xs
takeEnd count xs = drop (length xs - count) xs
unmatched xs = drop matchTop $ dropEnd matchBottom xs
Expand Down

0 comments on commit 66e8148

Please sign in to comment.