diff options
Diffstat (limited to 'app/History.hs')
-rw-r--r-- | app/History.hs | 69 |
1 files changed, 18 insertions, 51 deletions
diff --git a/app/History.hs b/app/History.hs index 70fc123..5b2dab3 100644 --- a/app/History.hs +++ b/app/History.hs @@ -26,14 +26,12 @@ import Git.CommitHash (CommitHash (..)) import Git.CommitHash qualified as C import Issue qualified as I import Issue.Parser qualified as I -import Issue.Provenance qualified as I import Issue.Tag qualified as I import Issue.Text qualified as I import IssueEvent (IssueEvent (..)) import Patch qualified as A import Process (proc, sh) import Render qualified as P -import System.Directory (getCurrentDirectory) import System.FilePath ((</>)) import System.IO.Temp (withSystemTempDirectory) import System.Process.Typed (setWorkingDir) @@ -97,35 +95,31 @@ data Scramble = Scramble deriving (Show, Binary, Generic) getScrambleOf :: CommitHash -> IO Scramble -getScrambleOf commitHash@WorkingTree = do - (issues, filesChanged) <- getIssuesAndFilesWorkingTreeChanged [] - pure $ Scramble {..} -getScrambleOf commitHash@(Commit hash) = do - (issues, filesChanged) <- getIssuesAndFilesCommitChanged hash +getScrambleOf commitHash = do + (issues, filesChanged) <- getIssuesAndFilesChanged commitHash pure $ Scramble {..} --- | 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 :: T.Text -> IO ([I.Issue], [FilePath]) -getIssuesAndFilesCommitChanged hash = do - withSystemTempDirectory "history" $ \tmp -> do - let cwd = tmp </> T.unpack hash - Git.withWorkingTree cwd hash do - files <- gitShowChanged cwd - issues <- concat <$> catch (mapM (getIssues cwd) files) dieOfInvalidTreeGrepperResult - pure (issues, files) +getIssuesAndFilesChanged :: CommitHash -> IO ([I.Issue], [FilePath]) +getIssuesAndFilesChanged commitHash = do + files <- Git.getChangedFilesOf commitHash + issues <- + concat + <$> catch + (mapM (getIssues commitHash) files) + (\(e :: E.InvalidTreeGrepperResult) -> die (show e)) + pure (issues, files) -- | Get all issues in the given directory and file. -getIssues :: FilePath -> FilePath -> IO [I.Issue] -getIssues cwd filename = +getIssues :: CommitHash -> FilePath -> IO [I.Issue] +getIssues commitHash filename = handle (\(_ :: E.UnknownFileExtension) -> pure []) $ - fmap catMaybes . mapM (fromComment cwd) - =<< G.getComments cwd filename + fmap catMaybes . mapM (fromComment commitHash) + =<< G.getComments commitHash filename -- | Note that `provenance` is trivial and needs to be fixed up later. -fromComment :: FilePath -> G.Comment -> IO (Maybe I.Issue) -fromComment cwd comment = do - commit <- I.commitFromHEAD cwd +fromComment :: CommitHash -> G.Comment -> IO (Maybe I.Issue) +fromComment commitHash comment = do + commit <- Git.getCommitOf commitHash let provenance = I.Provenance commit commit pure $ @@ -151,33 +145,6 @@ fromComment cwd comment = do where (commentStyle, rawText) = G.uncomment comment.file_type comment.text -dieOfInvalidTreeGrepperResult :: E.InvalidTreeGrepperResult -> IO a -dieOfInvalidTreeGrepperResult (E.InvalidTreeGrepperResult e) = - die e - --- | Gets issues in all files which have been changed in your current --- [working --- - tree](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefworkingtreeaworkingtree) -getIssuesAndFilesWorkingTreeChanged :: [FilePath] -> IO ([I.Issue], [FilePath]) -getIssuesAndFilesWorkingTreeChanged paths = do - cwd <- getCurrentDirectory - files <- gitLsFilesModifiedIn cwd paths - issues <- concat <$> catch (mapM (getIssues cwd) files) dieOfInvalidTreeGrepperResult - pure (issues, files) - -gitShowChanged :: FilePath -> IO [FilePath] -gitShowChanged cwd = - map T.unpack . T.lines . T.decodeUtf8 . LB.toStrict - <$> sh ("git show -p --name-only --format=''" & setWorkingDir cwd) - -gitLsFilesModifiedIn :: FilePath -> [FilePath] -> IO [FilePath] -gitLsFilesModifiedIn cwd paths = - map T.unpack . T.lines . T.decodeUtf8 . LB.toStrict - <$> sh - ( proc "git ls-files --modified %" ("--" : paths) - & setWorkingDir cwd - ) - propagate :: CommitHash -> History -> Scramble -> IO History propagate commitHash oldHistory scramble = do let issues = propagateIssues oldHistory.issues scramble |