diff --git a/src/Vervis/Git.hs b/src/Vervis/Git.hs index 93521e9..e9f4dc5 100644 --- a/src/Vervis/Git.hs +++ b/src/Vervis/Git.hs @@ -217,28 +217,39 @@ ep2fp = T.unpack . decodeUtf8 . B.intercalate "/" . map toBytes unModePerm :: ModePerm -> Word32 unModePerm (ModePerm w) = w +data Line = Line + { lineNumber :: Int + , lineText :: Text + } + +instance Eq Line where + Line _ t == Line _ s = t == s + +instance Ord Line where + Line _ t `compare` Line _ s = t `compare` s + mkdiff :: [Text] -> [Text] -> [(Bool, Int, Hunk)] mkdiff old new = let eitherOldNew (Old a) = Just $ Left a eitherOldNew (New a) = Just $ Right a eitherOldNew (Both _ _) = Nothing - stripLineNumber = fmap snd + stripLineNumber = fmap lineText mkhunk' (adds, pairs, rems) = Hunk { hunkAddFirst = stripLineNumber adds , hunkRemoveAdd = map (stripLineNumber *** stripLineNumber) pairs , hunkRemoveLast = stripLineNumber rems } - line ((n, _):_, _ , _) = (True, n) - line ([] , ((n, _) :| _, _):_, _) = (False, n) - line ([] , [] , (n, _):_) = (False, n) - line ([] , [] , []) = error "empty hunk" + line ((Line n _):_, _ , _) = (True, n) + line ([] , ((Line n _) :| _, _):_, _) = (False, n) + line ([] , [] , (Line n _):_) = (False, n) + line ([] , [] , []) = error "empty hunk" mkhunk h = let (n, l) = line h in (n, l, mkhunk' h) in map (mkhunk . groupEithers . N.toList) $ groupJusts $ map eitherOldNew $ - diff (zip [1..] old) (zip [1..] new) + diff (zipWith Line [1..] old) (zipWith Line [1..] new) accumEdits :: BlobStateDiff -> [Edit] -> [Edit] accumEdits (OnlyOld bs) es =