From 2bbd2f8b692dd952903a9f1527f2779a916118ab Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 13 Dec 2023 03:47:14 +0100 Subject: chore: uncache large issue fields --- app/Git.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index be95f61..6431259 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -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))) -- cgit v1.2.3