diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-16 14:20:23 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-16 14:21:23 +0200 |
commit | 82737c98e809bb3e970aa16750aa70f1adcfa03a (patch) | |
tree | f0b6d5f2352ff6b62f5bc5113b989c3c9b479055 /app/History.hs | |
parent | b0112000b3f2966489bbf5ac1f2e15815f463d06 (diff) |
refactor `Git.withWorkingTree`
Diffstat (limited to 'app/History.hs')
-rw-r--r-- | app/History.hs | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/app/History.hs b/app/History.hs index ff7f889..4f62610 100644 --- a/app/History.hs +++ b/app/History.hs @@ -10,12 +10,13 @@ import Data.Maybe (catMaybes, mapMaybe) import Data.Text (Text, append, isPrefixOf, lines, pack, unpack) import Data.Text.Encoding (decodeUtf8) import GHC.Generics (Generic) +import Git qualified import Issue (Issue (..), fromMatch, id) import Issue.Filter (Filter, applyFilter) -import Issue.Tag qualified as I import Issue.Sort (Sort, applySort) +import Issue.Tag qualified as I import Parallel (parMapM) -import Process (proc, sh, sh_) +import Process (proc, sh) import System.Directory (createDirectoryIfMissing, doesFileExist, getCurrentDirectory) import System.Exit (ExitCode (ExitFailure), exitWith) import System.FilePath (takeExtension, (</>)) @@ -220,25 +221,21 @@ getIssuesAndFilesWorkingTreeChanged paths = do getIssuesCommitAll :: Text -> IO [Issue] getIssuesCommitAll hash = do withSystemTempDirectory "history" $ \tmp -> do - cwd <- do - let cwd = tmp </> unpack hash - sh_ $ proc "git worktree add --detach % %" cwd (unpack hash) - pure cwd - files <- gitLsFilesAll cwd - concat <$> catch (getIssuesPar cwd files) (dieOfInvalidTreeGrepperResult) + let cwd = tmp </> unpack hash + Git.withWorkingTree cwd hash do + files <- gitLsFilesAll cwd + concat <$> catch (getIssuesPar cwd files) (dieOfInvalidTreeGrepperResult) -- | Given the hash of a commit, get all issues in the files which have -- been changed by this commit, as well as all changed files. getIssuesAndFilesCommitChanged :: Text -> IO ([Issue], [FilePath]) getIssuesAndFilesCommitChanged hash = do withSystemTempDirectory "history" $ \tmp -> do - cwd <- do - let cwd = tmp </> unpack hash - sh_ $ proc "git worktree add --detach % %" cwd (unpack hash) - pure cwd - files <- gitShowChanged cwd - issues <- concat <$> catch (getIssuesPar cwd files) (dieOfInvalidTreeGrepperResult) - pure (issues, files) + let cwd = tmp </> unpack hash + Git.withWorkingTree cwd hash do + files <- gitShowChanged cwd + issues <- concat <$> catch (getIssuesPar cwd files) (dieOfInvalidTreeGrepperResult) + pure (issues, files) gitLsFilesAll :: FilePath -> IO [FilePath] gitLsFilesAll cwd = |