1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-28 12:34:50 +09:00

Ignore line numbers when computing diff

This commit is contained in:
fr33domlover 2018-05-21 20:54:05 +00:00
parent 9f77ea69cb
commit b398f05ecc

View file

@ -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 =