From f92c593a3d2c4bdb023fdd834b6e8c874d063cc8 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 29 Feb 2024 04:11:10 +0100 Subject: feat: add `review` command Prototype of the `review` command, cf. `anissue review -h`. Also adds the `status` command. --- app/Git.hs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index 6431259..7859503 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -8,6 +8,9 @@ module Git getCommitOf, readTextFileOfText, readTextFileOfBS, + resolveRef, + getCommitsBetween, + diffOf, ) where @@ -27,6 +30,7 @@ import Data.Time.Clock (UTCTime, getCurrentTime) import Exception qualified as E import GHC.Generics (Generic) import Git.CommitHash +import Patch qualified as A import Process (proc, sh) import Text.Printf (printf) @@ -91,7 +95,7 @@ readTextFileOfText :: CommitHash -> FilePath -> IO LT.Text readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString -readTextFileOfBS = readTextFileOf LB.readFile (\x->x) +readTextFileOfBS = readTextFileOf LB.readFile (\x -> x) readTextFileOf :: (FilePath -> IO a) -> (LB.ByteString -> a) -> CommitHash -> FilePath -> IO a readTextFileOf readFile _ WorkingTree filePath = @@ -102,3 +106,20 @@ readTextFileOf _ decode (Commit hash) filePath = catch (decode <$> sh (proc "git show %:%" hash filePath)) (\(_ :: E.ProcessException) -> throwIO (E.CannotReadFile (printf "%s:%s" hash filePath))) + +resolveRef :: T.Text -> IO CommitHash +resolveRef = + fmap (Commit . T.strip . T.decodeUtf8 . LB.toStrict) + . sh + . proc "git rev-parse %" + +-- TODO Throw if `prevHash` is not an ancestor of `hash`. +getCommitsBetween :: CommitHash -> CommitHash -> IO [CommitHash] +getCommitsBetween (Commit prevHash) (Commit hash) = do + map (Commit . T.strip) . T.lines . T.decodeUtf8 . LB.toStrict + <$> sh (proc "git log --format=%%H %..%" prevHash hash) + +diffOf :: CommitHash -> CommitHash -> IO A.Patch +diffOf prevHash hash = + A.parse . T.decodeUtf8 . LB.toStrict + <$> sh (proc "git diff % %" (toTextUnsafe prevHash) (toTextUnsafe hash)) -- cgit v1.2.3 From a2f401ca9839b6041b7d94f77de4530f168b12ad Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Wed, 6 Mar 2024 13:47:17 +0100 Subject: review(feature/review): approve lgtm, possible splitting some non-business-logic stuff into separate commits would be nice commit 9a49ec0dcd6f75736949350844f85d80fe48a662 --- app/Git.hs | 1 + 1 file changed, 1 insertion(+) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index 7859503..fd4fa53 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -96,6 +96,7 @@ readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString readTextFileOfBS = readTextFileOf LB.readFile (\x -> x) +-- REVIEW Suggestion: we could use `id` instead of `\x -> x` readTextFileOf :: (FilePath -> IO a) -> (LB.ByteString -> a) -> CommitHash -> FilePath -> IO a readTextFileOf readFile _ WorkingTree filePath = -- cgit v1.2.3 From 7f0066cafd2a91959ef618ef8342524ca30a328f Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 13 Mar 2024 06:16:50 +0100 Subject: review: request-changes feature/review --- app/Git.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index fd4fa53..eae3a85 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -95,8 +95,12 @@ readTextFileOfText :: CommitHash -> FilePath -> IO LT.Text readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString -readTextFileOfBS = readTextFileOf LB.readFile (\x -> x) +readTextFileOfBS = readTextFileOf LB.readFile id -- REVIEW Suggestion: we could use `id` instead of `\x -> x` +-- +-- REVIEW OK! +-- +-- RESOLVED readTextFileOf :: (FilePath -> IO a) -> (LB.ByteString -> a) -> CommitHash -> FilePath -> IO a readTextFileOf readFile _ WorkingTree filePath = -- cgit v1.2.3 From 1821aca5ef5451d0b1943c8640c5eb1f6fa7bbee Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 14 Mar 2024 06:52:32 +0100 Subject: chore: resolve TODOs --- app/Git.hs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index eae3a85..2e8fa82 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -31,7 +31,7 @@ import Exception qualified as E import GHC.Generics (Generic) import Git.CommitHash import Patch qualified as A -import Process (proc, sh) +import Process (proc, sh, sh_) import Text.Printf (printf) getCommitHashes :: IO (NonEmpty T.Text) @@ -96,6 +96,7 @@ readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString readTextFileOfBS = readTextFileOf LB.readFile id + -- REVIEW Suggestion: we could use `id` instead of `\x -> x` -- -- REVIEW OK! @@ -118,9 +119,20 @@ resolveRef = . sh . proc "git rev-parse %" --- TODO Throw if `prevHash` is not an ancestor of `hash`. +-- | `getCommitsBetween prevCommit commit` returns the commits from `prevCommit` to `commit`. The result excludes `prevCommit`, but includes `commit`. +-- +-- If `prevCommit` is not an ancestor of `commit`, this functions throws `NoAncestor commit prevCommit`. getCommitsBetween :: CommitHash -> CommitHash -> IO [CommitHash] -getCommitsBetween (Commit prevHash) (Commit hash) = do +getCommitsBetween WorkingTree commit@(Commit _) = + throwIO (E.NoAncestor WorkingTree commit) +getCommitsBetween WorkingTree WorkingTree = pure [WorkingTree] +getCommitsBetween prevCommit WorkingTree = + fmap (++ [WorkingTree]) . getCommitsBetween prevCommit + =<< resolveRef "HEAD" +getCommitsBetween prevCommit@(Commit prevHash) commit@(Commit hash) = do + catch + (sh_ (proc "git merge-base --is-ancestor % %" prevHash hash)) + (\(_ :: E.ProcessException) -> throwIO (E.NoAncestor commit prevCommit)) map (Commit . T.strip) . T.lines . T.decodeUtf8 . LB.toStrict <$> sh (proc "git log --format=%%H %..%" prevHash hash) -- cgit v1.2.3 From 09e26c37de7e7227d856ffe15c9554af36b50c58 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 14 Mar 2024 07:07:28 +0100 Subject: review: request-changes feature/review --- app/Git.hs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index 2e8fa82..e195d1b 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -97,12 +97,6 @@ readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString readTextFileOfBS = readTextFileOf LB.readFile id --- REVIEW Suggestion: we could use `id` instead of `\x -> x` --- --- REVIEW OK! --- --- RESOLVED - readTextFileOf :: (FilePath -> IO a) -> (LB.ByteString -> a) -> CommitHash -> FilePath -> IO a readTextFileOf readFile _ WorkingTree filePath = catch -- cgit v1.2.3