git-annex/Annex.hs

52 lines
1.1 KiB
Haskell
Raw Normal View History

2010-10-14 07:18:11 +00:00
{- git-annex monad -}
2010-10-10 19:04:07 +00:00
2010-10-11 21:52:46 +00:00
module Annex (
2010-10-14 07:18:11 +00:00
new,
run,
gitRepo,
gitRepoChange,
backends,
backendsChange,
2010-10-11 21:52:46 +00:00
) where
2010-10-10 19:04:07 +00:00
2010-10-14 07:18:11 +00:00
import Control.Monad.State
2010-10-14 06:36:41 +00:00
import qualified GitRepo as Git
2010-10-14 07:18:11 +00:00
import Types
import qualified BackendTypes as Backend
2010-10-14 20:13:43 +00:00
{- Create and returns an Annex state object for the specified git repo.
-}
new :: Git.Repo -> IO AnnexState
new g = do
let s = Backend.AnnexState { Backend.repo = g, Backend.backends = [] }
(_,s') <- Annex.run s (prep g)
return s'
where
prep g = do
-- read git config and update state
g' <- liftIO $ Git.configRead g
Annex.gitRepoChange g'
2010-10-14 07:18:11 +00:00
-- performs an action in the Annex monad
run state action = runStateT (action) state
-- Annex monad state accessors
gitRepo :: Annex Git.Repo
gitRepo = do
state <- get
return (Backend.repo state)
gitRepoChange :: Git.Repo -> Annex ()
gitRepoChange r = do
state <- get
put state { Backend.repo = r }
return ()
backends :: Annex [Backend]
backends = do
state <- get
return (Backend.backends state)
backendsChange :: [Backend] -> Annex ()
backendsChange b = do
state <- get
put state { Backend.backends = b }
return ()