diff options
-rw-r--r-- | app/History.hs | 50 |
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 |