1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 08:25:19 +03:00

Add a truncatePatch function

This commit is contained in:
joshvera 2016-04-01 15:35:09 -04:00
parent 7947bc1911
commit a18c2649d3
2 changed files with 12 additions and 1 deletions

View File

@ -22,6 +22,12 @@ printDiff parser arguments sources = case format arguments of
Patch -> diffFiles parser P.patch sources Patch -> diffFiles parser P.patch sources
JSON -> diffFiles parser J.json sources JSON -> diffFiles parser J.json sources
truncatedDiff :: DiffArguments -> Both SourceBlob -> IO Text
truncatedDiff arguments sources = case format arguments of
Split -> return ""
Patch -> return $ P.truncatePatch arguments sources
JSON -> return "{}"
printDiff' :: Parser -> DiffArguments -> Both SourceBlob -> IO () printDiff' :: Parser -> DiffArguments -> Both SourceBlob -> IO ()
printDiff' parser arguments sources = case format arguments of printDiff' parser arguments sources = case format arguments of
Split -> put (output arguments) =<< diffFiles parser split sources Split -> put (output arguments) =<< diffFiles parser split sources

View File

@ -1,7 +1,8 @@
module Renderer.Patch ( module Renderer.Patch (
patch, patch,
hunks, hunks,
Hunk(..) Hunk(..),
truncatePatch
) where ) where
import Alignment import Alignment
@ -22,6 +23,10 @@ import Data.Maybe
import Data.Monoid import Data.Monoid
import Data.Text (pack, Text) import Data.Text (pack, Text)
-- | Render a timed out file as a truncated diff.
truncatePatch :: DiffArguments -> Both SourceBlob -> Text
truncatePatch arguments blobs = pack $ header blobs ++ "#timed_out\nTruncating diff: timeout reached.\n"
-- | Render a diff in the traditional patch format. -- | Render a diff in the traditional patch format.
patch :: Renderer a Text patch :: Renderer a Text
patch diff blobs = pack $ case getLast (foldMap (Last . Just) string) of patch diff blobs = pack $ case getLast (foldMap (Last . Just) string) of