diff options
Diffstat (limited to 'app/Git.hs')
-rw-r--r-- | app/Git.hs | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -6,7 +6,8 @@ module Git Commit (..), Author (..), getCommitOf, - readTextFileOf, + readTextFileOfText, + readTextFileOfBS, ) where @@ -28,7 +29,6 @@ import GHC.Generics (Generic) import Git.CommitHash import Process (proc, sh) import Text.Printf (printf) -import Prelude hiding (lines) getCommitHashes :: IO (NonEmpty T.Text) getCommitHashes = fromMaybe (throw E.NoCommits) . N.nonEmpty . reverse . T.lines . T.decodeUtf8 . LB.toStrict <$> sh "git log --format=%H" @@ -87,12 +87,18 @@ getCommitOf commitHash@(Commit hash) = do } _ -> throwIO E.NoCommits -readTextFileOf :: CommitHash -> FilePath -> IO LT.Text -readTextFileOf WorkingTree filePath = +readTextFileOfText :: CommitHash -> FilePath -> IO LT.Text +readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 + +readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString +readTextFileOfBS = readTextFileOf LB.readFile (\x->x) + +readTextFileOf :: (FilePath -> IO a) -> (LB.ByteString -> a) -> CommitHash -> FilePath -> IO a +readTextFileOf readFile _ WorkingTree filePath = catch - (LT.readFile filePath) + (readFile filePath) (\(_ :: IOException) -> throwIO (E.CannotReadFile filePath)) -readTextFileOf (Commit hash) filePath = +readTextFileOf _ decode (Commit hash) filePath = catch - (LT.decodeUtf8 <$> sh (proc "git show %:%" hash filePath)) + (decode <$> sh (proc "git show %:%" hash filePath)) (\(_ :: E.ProcessException) -> throwIO (E.CannotReadFile (printf "%s:%s" hash filePath))) |