more namespace cleanup

This commit is contained in:
Joey Hess 2010-10-14 02:52:17 -04:00
parent 4c1d8b9689
commit 0b55bd05de
8 changed files with 49 additions and 39 deletions

View file

@ -14,4 +14,34 @@ module AbstractTypes (
Backend Backend
) where ) where
import Types import Control.Monad.State
import qualified GitRepo as Git
import BackendTypes
-- constructor
makeAnnexState :: Git.Repo -> AnnexState
makeAnnexState g = AnnexState { repo = g, backends = [] }
-- performs an action in the Annex monad
runAnnexState state action = runStateT (action) state
-- Annex monad state accessors
gitAnnex :: Annex Git.Repo
gitAnnex = do
state <- get
return (repo state)
gitAnnexChange :: Git.Repo -> Annex ()
gitAnnexChange r = do
state <- get
put state { repo = r }
return ()
backendsAnnex :: Annex [Backend]
backendsAnnex = do
state <- get
return (backends state)
backendsAnnexChange :: [Backend] -> Annex ()
backendsAnnexChange b = do
state <- get
put state { backends = b }
return ()

View file

@ -30,7 +30,8 @@ import BackendList
import Locations import Locations
import qualified GitRepo as Git import qualified GitRepo as Git
import Utility import Utility
import Types import AbstractTypes
import BackendTypes
{- Attempts to store a file in one of the backends. -} {- Attempts to store a file in one of the backends. -}
storeFile :: FilePath -> Annex (Maybe (Key, Backend)) storeFile :: FilePath -> Annex (Maybe (Key, Backend))

View file

@ -5,7 +5,7 @@ module BackendChecksum (backend) where
import qualified BackendFile import qualified BackendFile
import Data.Digest.Pure.SHA import Data.Digest.Pure.SHA
import Types import BackendTypes
-- based on BackendFile just with a different key type -- based on BackendFile just with a different key type
backend = BackendFile.backend { backend = BackendFile.backend {

View file

@ -7,7 +7,7 @@ import Control.Monad.State
import System.IO import System.IO
import System.Cmd import System.Cmd
import Control.Exception import Control.Exception
import Types import BackendTypes
import LocationLog import LocationLog
import Locations import Locations
import qualified Remotes import qualified Remotes

View file

@ -7,7 +7,7 @@ module BackendList (
lookupBackendName lookupBackendName
) where ) where
import Types import BackendTypes
-- When adding a new backend, import it here and add it to the list. -- When adding a new backend, import it here and add it to the list.
import qualified BackendFile import qualified BackendFile

View file

@ -1,12 +1,16 @@
{- git-annex core data types -} {- git-annex backend data types
-
- Mostly only backend implementations should need to import this.
-}
module Types where module BackendTypes where
import Control.Monad.State import Control.Monad.State
import Data.String.Utils import Data.String.Utils
import qualified GitRepo as Git import qualified GitRepo as Git
-- git-annex's runtime state -- git-annex's runtime state type doesn't really belong here,
-- but it uses Backend, so has to be here to avoid a depends loop.
data AnnexState = AnnexState { data AnnexState = AnnexState {
repo :: Git.Repo, repo :: Git.Repo,
backends :: [Backend] backends :: [Backend]
@ -15,33 +19,6 @@ data AnnexState = AnnexState {
-- git-annex's monad -- git-annex's monad
type Annex = StateT AnnexState IO type Annex = StateT AnnexState IO
-- constructor
makeAnnexState :: Git.Repo -> AnnexState
makeAnnexState g = AnnexState { repo = g, backends = [] }
-- performs an action in the Annex monad
runAnnexState state action = runStateT (action) state
-- Annex monad state accessors
gitAnnex :: Annex Git.Repo
gitAnnex = do
state <- get
return (repo state)
gitAnnexChange :: Git.Repo -> Annex ()
gitAnnexChange r = do
state <- get
put state { repo = r }
return ()
backendsAnnex :: Annex [Backend]
backendsAnnex = do
state <- get
return (backends state)
backendsAnnexChange :: [Backend] -> Annex ()
backendsAnnexChange b = do
state <- get
put state { backends = b }
return ()
-- annexed filenames are mapped into keys -- annexed filenames are mapped into keys
data Key = Key String deriving (Eq) data Key = Key String deriving (Eq)

View file

@ -6,7 +6,7 @@ module BackendUrl (backend) where
import Control.Monad.State import Control.Monad.State
import System.Cmd import System.Cmd
import IO import IO
import Types import BackendTypes
backend = Backend { backend = Backend {
name = "url", name = "url",

View file

@ -11,7 +11,8 @@ module Locations (
) where ) where
import Data.String.Utils import Data.String.Utils
import Types import AbstractTypes
import qualified BackendTypes as Backend
import qualified GitRepo as Git import qualified GitRepo as Git
{- Long-term, cross-repo state is stored in files inside the .git-annex {- Long-term, cross-repo state is stored in files inside the .git-annex
@ -32,7 +33,7 @@ annexLocation r backend key =
{- Annexed file's location relative to the gitWorkTree -} {- Annexed file's location relative to the gitWorkTree -}
annexLocationRelative :: Git.Repo -> Backend -> Key -> FilePath annexLocationRelative :: Git.Repo -> Backend -> Key -> FilePath
annexLocationRelative r backend key = annexLocationRelative r backend key =
Git.dir r ++ "/annex/" ++ (name backend) ++ "/" ++ (keyFile key) Git.dir r ++ "/annex/" ++ (Backend.name backend) ++ "/" ++ (keyFile key)
{- Converts a key into a filename fragment. {- Converts a key into a filename fragment.
- -
@ -50,4 +51,5 @@ keyFile key = replace "/" "%" $ replace "%" "&s" $ replace "&" "&a" $ show key
{- Reverses keyFile, converting a filename fragment (ie, the basename of {- Reverses keyFile, converting a filename fragment (ie, the basename of
- the symlink target) into a key. -} - the symlink target) into a key. -}
fileKey :: FilePath -> Key fileKey :: FilePath -> Key
fileKey file = Key $ replace "&a" "&" $ replace "&s" "%" $ replace "%" "/" file fileKey file = Backend.Key $
replace "&a" "&" $ replace "&s" "%" $ replace "%" "/" file