aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/Git.hs9
-rw-r--r--app/History/PartialCommitInfo.hs9
2 files changed, 8 insertions, 10 deletions
diff --git a/app/Git.hs b/app/Git.hs
index af02b70..653ddbd 100644
--- a/app/Git.hs
+++ b/app/Git.hs
@@ -5,11 +5,14 @@ module Git
)
where
-import Control.Exception (finally)
+import Control.Exception (finally, throw)
import Data.ByteString.Lazy.Char8 qualified as LB8
+import Data.List.NonEmpty (NonEmpty)
+import Data.List.NonEmpty qualified as N
import Data.Maybe (fromMaybe)
import Data.Text qualified as T
import Data.Text.Encoding qualified as T
+import Exception qualified as E
import Process (proc, sh, sh_)
import System.Directory (createDirectoryIfMissing)
import System.FilePath (dropTrailingPathSeparator, takeDirectory)
@@ -22,8 +25,8 @@ withWorkingTree path hash action = do
action `finally` do
sh_ $ proc "git worktree remove --force %" path
-getCommitHashes :: IO [T.Text]
-getCommitHashes = T.lines . T.decodeUtf8 . LB8.toStrict <$> sh "git log --format=%H"
+getCommitHashes :: IO (NonEmpty T.Text)
+getCommitHashes = fromMaybe (throw E.NoCommits) . N.nonEmpty . reverse . T.lines . T.decodeUtf8 . LB8.toStrict <$> sh "git log --format=%H"
getRootDir :: IO FilePath
getRootDir = T.unpack . stripTrailingNL . T.decodeUtf8 . LB8.toStrict <$> sh (proc "git rev-parse --show-toplevel")
diff --git a/app/History/PartialCommitInfo.hs b/app/History/PartialCommitInfo.hs
index 2337ef7..cd8cd46 100644
--- a/app/History/PartialCommitInfo.hs
+++ b/app/History/PartialCommitInfo.hs
@@ -8,6 +8,7 @@ import Control.Exception (catch)
import Data.Binary (Binary)
import Data.ByteString.Lazy.Char8 qualified as LB8
import Data.Function ((&))
+import Data.List.NonEmpty qualified as N
import Data.Text qualified as T
import Die (die)
import Exception qualified as E
@@ -35,13 +36,7 @@ data PartialCommitInfo = PartialCommitInfo
getPartialCommitInfos :: IO [PartialCommitInfo]
getPartialCommitInfos = do
- -- TODO Revise `getCommitHashes`
- --
- -- - Should throw if no commits.
- -- - Should always be reversed?
- --
- -- @difficulty easy
- commitHashes <- reverse <$> Git.getCommitHashes
+ commitHashes <- N.toList <$> Git.getCommitHashes
parMapM getCommitInfoOf (map Commit commitHashes ++ [WorkingTree])
getCommitInfoOf :: CommitHash -> IO PartialCommitInfo