diff options
Diffstat (limited to 'src/Repo.hs')
-rw-r--r-- | src/Repo.hs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/Repo.hs b/src/Repo.hs index c8e818c..1053248 100644 --- a/src/Repo.hs +++ b/src/Repo.hs @@ -1,10 +1,14 @@ module Repo ( - Repo, Commit, commitId, + Repo, + DeclaredRepo(..), + RepoName(..), textRepoName, showRepoName, + Commit, commitId, CommitId, textCommitId, showCommitId, TreeId, textTreeId, showTreeId, Tag(..), openRepo, + readCommit, readBranch, readTag, listCommits, @@ -53,6 +57,21 @@ data Repo , gitWatchedBranches :: MVar (Map Text [ TVar (Maybe Commit) ]) } +data DeclaredRepo = DeclaredRepo + { repoName :: RepoName + , repoPath :: FilePath + } + +newtype RepoName = RepoName Text + deriving (Eq, Ord) + +textRepoName :: RepoName -> Text +textRepoName (RepoName text) = text + +showRepoName :: RepoName -> String +showRepoName = T.unpack . textRepoName + + data Commit = Commit { commitRepo :: Repo , commitId_ :: CommitId @@ -133,6 +152,12 @@ mkCommit commitRepo commitId_ = do commitDetails <- newMVar Nothing return $ Commit {..} +readCommit :: MonadIO m => Repo -> Text -> m (Maybe Commit) +readCommit repo@GitRepo {..} ref = liftIO $ do + readProcessWithExitCode "git" [ "--git-dir=" <> gitDir, "rev-parse", "--verify", "--quiet", T.unpack ref <> "^{commit}" ] "" >>= \case + ( ExitSuccess, out, _ ) | cid : _ <- lines out -> Just <$> mkCommit repo (CommitId $ BC.pack cid) + _ -> return Nothing + readCommitFromFile :: MonadIO m => Repo -> FilePath -> m (Maybe Commit) readCommitFromFile repo@GitRepo {..} path = liftIO $ do try @IOException (BC.readFile $ gitDir </> path) >>= \case |