aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Fabian Kirchner <kirchner@posteo.de>2023-10-14 14:28:12 +0200
committerLibravatar Fabian Kirchner <kirchner@posteo.de>2023-10-14 14:28:12 +0200
commitf9238c373f505c44b569bc587d610972f7e20b85 (patch)
treed629f8525090c1d8af951a6d453d51795366de3e /app
parente8787affc807cb640a69a5c30a673580ab1551f3 (diff)
refactor: split extract listIssuesCurrent from listIssuesOf
Diffstat (limited to 'app')
-rw-r--r--app/History.hs50
1 files changed, 25 insertions, 25 deletions
diff --git a/app/History.hs b/app/History.hs
index a59a5f1..396c309 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -50,9 +50,9 @@ listIssues filters files = do
( \maybeCommit ->
case maybeCommit of
Nothing ->
- listIssuesOf Nothing files
+ listIssuesCurrent files
Just commit ->
- cached commit (\_ -> listIssuesOf (Just commit) files)
+ cached commit (\_ -> listIssuesOf commit)
)
$ (:) Nothing
$ map Just commits
@@ -94,33 +94,29 @@ cached commit func = do
encodeFile file blob
pure blob
-listIssuesOf :: Maybe Text -> [FilePath] -> IO [Issue]
-listIssuesOf maybeCommit files = do
- issue <- withSystemTempDirectory "history" $ \tmp -> do
- worktree <-
- case maybeCommit of
- Nothing ->
- getCurrentDirectory
- Just commit -> do
- let worktree = tmp </> unpack commit
- sh_ (fromString (printf "git worktree add --detach %s %s" (quote worktree) (quote (unpack commit))))
- pure worktree
+listIssuesCurrent :: [FilePath] -> IO [Issue]
+listIssuesCurrent files = do
+ worktree <- getCurrentDirectory
+ concat
+ <$> catch
+ (getIssuesPar worktree =<< (getFiles worktree files))
+ (\(InvalidTreeGrepperResult e) -> die e)
+
+listIssuesOf :: Text -> IO [Issue]
+listIssuesOf commit = do
+ withSystemTempDirectory "history" $ \tmp -> do
+ worktree <- do
+ let worktree = tmp </> unpack commit
+ sh_ (fromString (printf "git worktree add --detach %s %s" (quote worktree) (quote (unpack commit))))
+ pure worktree
concat
<$> catch
- ( parMapM (handle forgetGetIssuesExceptions . getIssues worktree)
- =<< ( case maybeCommit of
- Nothing ->
- getFiles worktree files
- Just _ ->
- getFilesChanged worktree
- )
- )
+ (getIssuesPar worktree =<< (getFilesChanged worktree))
(\(InvalidTreeGrepperResult e) -> die e)
- pure issue
- where
- forgetGetIssuesExceptions :: UnknownFileExtension -> IO [a]
- forgetGetIssuesExceptions _ = pure []
+
+forgetGetIssuesExceptions :: UnknownFileExtension -> IO [a]
+forgetGetIssuesExceptions _ = pure []
getFiles :: FilePath -> [String] -> IO [FilePath]
getFiles cwd files =
@@ -144,6 +140,10 @@ getFilesChanged cwd =
& setWorkingDir cwd
)
+getIssuesPar :: FilePath -> [FilePath] -> IO [[Issue]]
+getIssuesPar worktree =
+ parMapM (handle forgetGetIssuesExceptions . getIssues worktree)
+
getIssues :: FilePath -> FilePath -> IO [Issue]
getIssues cwd filename = do
let extension = takeExtension filename