1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 09:55:52 +03:00

Add beforeFilepath and afterFilepath headers

This commit is contained in:
joshvera 2016-03-03 17:19:50 -05:00
parent 63bc5d72db
commit 1ba10ac22d

View File

@ -77,7 +77,7 @@ getRange (Pure patch) = let Info range _ :< _ = getSplitTerm patch in range
-- | Returns the header given two source blobs and a hunk. -- | Returns the header given two source blobs and a hunk.
header :: Both SourceBlob -> Hunk a -> String header :: Both SourceBlob -> Hunk a -> String
header blobs hunk = intercalate "\n" [filepathHeader, fileModeHeader, blobOidHeader, maybeOffsetHeader] header blobs hunk = intercalate "\n" [filepathHeader, fileModeHeader, blobOidHeader, beforeFilepath, afterFilepath, maybeOffsetHeader]
where filepathHeader = "diff --git a/" ++ pathA ++ " b/" ++ pathB where filepathHeader = "diff --git a/" ++ pathA ++ " b/" ++ pathB
fileModeHeader = case (modeA, modeB) of fileModeHeader = case (modeA, modeB) of
(Nothing, Just mode) -> "new file mode " ++ modeToDigits mode (Nothing, Just mode) -> "new file mode " ++ modeToDigits mode
@ -85,7 +85,15 @@ header blobs hunk = intercalate "\n" [filepathHeader, fileModeHeader, blobOidHea
(Just mode1, Just mode2) | mode1 == mode2 -> "index " ++ oidA ++ ".." ++ oidB (Just mode1, Just mode2) | mode1 == mode2 -> "index " ++ oidA ++ ".." ++ oidB
(Just mode1, Just mode2) -> "index " ++ oidA ++ ".." ++ oidB ++ " " ++ modeToDigits mode2 (Just mode1, Just mode2) -> "index " ++ oidA ++ ".." ++ oidB ++ " " ++ modeToDigits mode2
blobOidHeader = "index " ++ oidA ++ ".." ++ oidB blobOidHeader = "index " ++ oidA ++ ".." ++ oidB
maybeOffsetHeader = if lengthA > 0 && lengthB > 0 then offsetHeader else mempty beforeFilepath = "--- " ++ case modeA of
Just mode -> "a/" ++ pathA
Nothing -> "/dev/null"
afterFilepath = "+++ " ++ case modeB of
Just mode -> "b/" ++ pathB
Nothing -> "/dev/null"
maybeOffsetHeader = if lengthA > 0 && lengthB > 0
then offsetHeader
else mempty
offsetHeader = "@@ -" ++ show offsetA ++ "," ++ show lengthA ++ " +" ++ show offsetB ++ "," ++ show lengthB ++ " @@\n" offsetHeader = "@@ -" ++ show offsetA ++ "," ++ show lengthA ++ " +" ++ show offsetB ++ "," ++ show lengthB ++ " @@\n"
(lengthA, lengthB) = runBoth . fmap getSum $ hunkLength hunk (lengthA, lengthB) = runBoth . fmap getSum $ hunkLength hunk
(offsetA, offsetB) = runBoth . fmap getSum $ offset hunk (offsetA, offsetB) = runBoth . fmap getSum $ offset hunk