Ignore line numbers when computing diff
This commit is contained in:
parent
9f77ea69cb
commit
b398f05ecc
1 changed files with 17 additions and 6 deletions
|
@ -217,20 +217,31 @@ ep2fp = T.unpack . decodeUtf8 . B.intercalate "/" . map toBytes
|
||||||
unModePerm :: ModePerm -> Word32
|
unModePerm :: ModePerm -> Word32
|
||||||
unModePerm (ModePerm w) = w
|
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 :: [Text] -> [Text] -> [(Bool, Int, Hunk)]
|
||||||
mkdiff old new =
|
mkdiff old new =
|
||||||
let eitherOldNew (Old a) = Just $ Left a
|
let eitherOldNew (Old a) = Just $ Left a
|
||||||
eitherOldNew (New a) = Just $ Right a
|
eitherOldNew (New a) = Just $ Right a
|
||||||
eitherOldNew (Both _ _) = Nothing
|
eitherOldNew (Both _ _) = Nothing
|
||||||
stripLineNumber = fmap snd
|
stripLineNumber = fmap lineText
|
||||||
mkhunk' (adds, pairs, rems) = Hunk
|
mkhunk' (adds, pairs, rems) = Hunk
|
||||||
{ hunkAddFirst = stripLineNumber adds
|
{ hunkAddFirst = stripLineNumber adds
|
||||||
, hunkRemoveAdd = map (stripLineNumber *** stripLineNumber) pairs
|
, hunkRemoveAdd = map (stripLineNumber *** stripLineNumber) pairs
|
||||||
, hunkRemoveLast = stripLineNumber rems
|
, hunkRemoveLast = stripLineNumber rems
|
||||||
}
|
}
|
||||||
line ((n, _):_, _ , _) = (True, n)
|
line ((Line n _):_, _ , _) = (True, n)
|
||||||
line ([] , ((n, _) :| _, _):_, _) = (False, n)
|
line ([] , ((Line n _) :| _, _):_, _) = (False, n)
|
||||||
line ([] , [] , (n, _):_) = (False, n)
|
line ([] , [] , (Line n _):_) = (False, n)
|
||||||
line ([] , [] , []) = error "empty hunk"
|
line ([] , [] , []) = error "empty hunk"
|
||||||
mkhunk h =
|
mkhunk h =
|
||||||
let (n, l) = line h
|
let (n, l) = line h
|
||||||
|
@ -238,7 +249,7 @@ mkdiff old new =
|
||||||
in map (mkhunk . groupEithers . N.toList) $
|
in map (mkhunk . groupEithers . N.toList) $
|
||||||
groupJusts $
|
groupJusts $
|
||||||
map eitherOldNew $
|
map eitherOldNew $
|
||||||
diff (zip [1..] old) (zip [1..] new)
|
diff (zipWith Line [1..] old) (zipWith Line [1..] new)
|
||||||
|
|
||||||
accumEdits :: BlobStateDiff -> [Edit] -> [Edit]
|
accumEdits :: BlobStateDiff -> [Edit] -> [Edit]
|
||||||
accumEdits (OnlyOld bs) es =
|
accumEdits (OnlyOld bs) es =
|
||||||
|
|
Loading…
Reference in a new issue